Java Learning -- What is JNDI and java what is jndi
I once remembered that when I was working on the data center charging system, I came into contact with the API. Because of its powerful functions, I didn't know much about it, so I was so worried. Now, we can see that it is actually a group of interfaces. As long as we understand it, we will find that it is not as terrible as it is. Today, let's take a look at the java interface-JNDI.
Concept
Java Naming and Directory Interface (JNDI) is a set of APIs used to access name and Directory services from Java applications. The naming service associates names with objects so that the objects can be accessed by corresponding names. The directory service is a naming service with attributes and names for its objects.
The naming or directory service allows you to centrally manage the storage of shared information, which is important in network applications because it can make these applications more consistent and easy to manage. For example, you can store the printer configuration in the directory service so that all printer-related applications can use it.
Function
The J2EE specification requires that all J2EE containers provide the implementation of the jndi specification. The role of JNDI in J2EE is "Switch"-a general mechanism for J2EE components to find other components, resources, or services at runtime.
In most cases, the container that provides the JNDI supplier can act as a limited data storage, so that the administrator can set the execution attribute of the application, and let other applications reference these attributes (Java Management Extensions (JMX) can also be used for this purpose ). The primary role of JNDI in J2EE applications is to provide an indirect layer, so that components can discover the required resources without understanding these indirect properties.
In J2EE, JNDI is the binder that combines J2EE applications. The indirect addressing provided by JNDI allows cross-enterprise delivery of scalable, powerful, and flexible applications. This is the commitment of J2EE, and after some planning and pre-consideration, this commitment can be fully implemented.
PS: JNDI avoids tight coupling between programs and databases, making applications easier to configure and deploy.
Architecture
The JNDI architecture provides a standard API unrelated to the naming system, which is built on the driver specific to the naming system. This layer helps isolate the application from the actual data source. Therefore, no matter whether the application accesses LDAP, RMI, DNS, or other directory services, this does not matter. In other words, JNDI has nothing to do with any specific directory service implementation. You can use any directory as long as you have the corresponding service provider interface (or driver), as shown in.
Note that it is important to know about JNDI, that is, it provides both Application Programming Interface (API) and Service Provider Interface (SPI ). The practical significance of this is that for an application that interacts with the naming or directory service, there must be a JNDI service provider for the service, this is the stage where the jndi spi works. A service provider is basically a group of classes, these classes implement various JNDI interfaces for specific naming and directory services-similar to the JDBC driver's implementation of various JDBC interfaces for specific data systems. As an application developer, you do not need to worry about jndi spi .. You only need to ensure that you provide a service provider for each name or directory service you want to use.
Summary
1. The purpose of JNDI is to understand the root node, which is to develop applications that are easier to maintain, expand, and deploy.
2. JNDI is a specification (similar to jdbc) proposed by sun. It is implemented by various j2ee container providers. sun only requires that j2ee containers have the functions such as JNDI.
3. The role of JNDI In the j2ee system is a "Switch", which is a general mechanism for J2EE components to find other components, resources, or services at runtime.
4. JNDI is searched by the resource name. The resource name is unique throughout the j2ee application (in the j2ee container.