Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is JNDI? What is its basic use? When is it used?

Tags:

jndi

  • What is JNDI?

  • What is its basic use?

  • When is it used?

like image 427
LetsSyncUp Avatar asked Dec 06 '10 10:12

LetsSyncUp


People also ask

What is JNDI name example?

A name that is bound within a context is the JNDI name of the object. In Specifying a Resource Reference, for example, the JNDI name for the JDBC resource (or data source) is jdbc/ejbTutorialDB .

Why does JNDI exist?

JNDI is the Java Naming and Directory Interface. It's used to separate the concerns of the application developer and the application deployer. When you're writing an application which relies on a database, you shouldn't need to worry about the user name or password for connecting to that database.

Which file is used for JNDI lookup?

xml , or ejb-jar. xml for that application are available. This means that a lookup using java:comp/env works for any resource that the application has specified.

What is a JNDI context?

It is an API to providing access to a directory service, that is, a service mapping name (strings) with objects, reference to remote objects or simple data. This is called binding. The set of bindings is called the context. Applications use the JNDI interface to access resources.


2 Answers

What is JNDI ?

It stands for Java Naming and Directory Interface.

What is its basic use?

JNDI allows distributed applications to look up services in an abstract, resource-independent way.

When it is used?

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:

  1. If you have a deployment sequence where apps move from 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.
  2. You can minimize the number of folks who need to know the credentials for accessing a production database. Only the Java EE app server needs to know if you use JNDI.
like image 93
duffymo Avatar answered Nov 29 '22 10:11

duffymo


What is JNDI ?

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.

What is its basic use?

Most of it is covered in the above answer but I would like to provide architecture here so that above will make more sense.

enter image description here

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:

  1. Lightweight Directory Access Protocol (LDAP)
  2. Common Object Request Broker Architecture (CORBA) Common Object Services (COS) name service
  3. Java Remote Method Invocation (RMI) Registry

So basically you create objects and register them on the directory services which you can later do lookup and execute operation on.

like image 44
Aniket Thakur Avatar answered Nov 29 '22 11:11

Aniket Thakur