What is JNDI ? What is its basic use? When is it used?
相关问题
- Why does Hibernate perform a JNDI lookup?
- Spring Boot JNDI resource-ref
- JBoss 7: JNDI lookup
- How to limit number of rows returned from Oracle a
- How do I set up a mock queue using mockrunner to t
相关文章
- Best way to manage DB connections without JNDI
- Multiple dynamic data sources for a servlet contex
- How can you store credentials in a JNDI lookup?
- @Remote JNDI Communication: Wildfly to JBoss AS 5.
- Tomcat 6/7 JNDI with multiple datasources
- How to show all objectclasses description of ldap
- spring jndi NamingException: Name [spring.liveBean
- Adding LDAP entries using JNDI
What is JNDI ?
JNDI stands for Java Naming and Directory Interface. It comes standard with J2EE.
What is its basic use?
With this API, you can access many types of data, like objects, devices, files of naming and directory services, eg. it is used by EJB to find remote objects. JNDI is designed to provide a common interface to access existing services like DNS, NDS, LDAP, CORBA and RMI.
When it is used?
You can use the JNDI to perform naming operations, including read operations and operations for updating the namespace. The following operations are described here.
JNDI in layman's terms is basically an Interface for being able to get instances of internal/External resources such as
or any other type defined by a JCA resource adapter. It provides a syntax in being able to create access whether they are internal or external. i.e (comp/env in this instance means where component/environment, there are lots of other syntax):
The Java Naming and Directory InterfaceTM (JNDI) is an application programming interface (API) that provides naming and directory functionality to applications written using the JavaTM programming language. It is defined to be independent of any specific directory service implementation. Thus a variety of directories(new, emerging, and already deployed) can be accessed in a common way.
Most of it is covered in the above answer but I would like to provide architecture here so that above will make more sense.
To use the JNDI, you must have the JNDI classes and one or more service providers. The Java 2 SDK, v1.3 includes three service providers for the following naming/directory services:
So basically you create objects and register them on the directory services which you can later do lookup and execute operation on.
A naming service associates names with objects and finds objects based on their given names.(RMI registry is a good example of a naming service.) JNDI provides a common interface to many existing naming services, such as LDAP, DNS.
Without JNDI, the location or access information of remote resources would have to be hard-coded in applications or made available in a configuration. Maintaining this information is quite tedious and error prone.
JNDI Overview
Reference
It stands for Java Naming and Directory Interface.
JNDI allows distributed applications to look up services in an abstract, resource-independent way.
The most common use case is to set up a database connection pool on a Java EE application server. Any application that's deployed on that server can gain access to the connections they need using the JNDI name
java:comp/env/FooBarPool
without having to know the details about the connection.This has several advantages:
devl->int->test->prod
environments, you can use the same JNDI name in each environment and hide the actual database being used. Applications don't have to change as they migrate between environments.