Java Naming and Directory Interface
Java Naming and Directory Interface ( JNDI ) is an application programming interface (API) within the Java programming language for naming services and directory services. Using this interface, data and object references can be filed based on a name and accessed by users of the interface.
The interface is independent of the actual implementation. Rather, JNDI is a so-called Service Provider Interface (SPI ) that allows manufacturers to integrate their own solutions in this framework.
In practice, JNDI is mainly used to search databases and registration, distributed objects on a network and call via Remote Method Invocation.
The API includes:
- A mechanism for binding an object to a name
- Methods for the retrieval of information based on a name
- An event concept, to be informed about the client about changes
- Special extensions for LDAP functionality
JNDI enables the support of virtually all kinds of naming and directory services, in particular by:
- Lightweight Directory Access Protocol (LDAP)
- Domain Name System (DNS)
- Network Information Service (NIS)
- Common Object Request Broker Architecture (CORBA ) naming service
- File system
JNDI Lookup
Lookup is the process by which the named objects be determined ( English for " Lookup ").
In the JNDI names are arranged hierarchically. Names are usually strings like " com.mydomain.MyBean ", but can also be any object that implements the interface javax.naming.Name. In the name or directory service, either the assigned object itself is stored for each name or a JNDI reference to the associated object. The programming interface from JNDI ( " JNDI API") defines where to look for the object. The initial context is it usually the starting point.
In the simplest case, an initial context is sufficient to search for a name:
Hashtable args = new Hashtable (); / / First need the context factory and thus the / / Implementation of the JNDI provider will be defined: args.put ( Context.INITIAL_CONTEXT_FACTORY, " com.jndiprovider.TheirContextFactory "); / / Then the URL that defines where to find the data: args.put ( Context.PROVIDER_URL, " jndiprovider -database "); / / So that you get in the simplest case, the initial context: Context myCurrentContext = new InitialContext ( args); / / Using this context can then objects / / That have been previously linked to the context, see: Object reference = myCurrentContext.lookup ( " com.mydomain.MyBean "); see also
- Spring ( Framework) - declarative use of JNDI