Java - Java Naming and Directory Interface (JNDI)

> Procedural Languages > Java

1 - About

JNDI is an interface describing naming and directory functionalities.

It provides applications with methods for performing standard directory operations, such as:

  • associating attributes with objects
  • and searching for objects using their attributes.

The implementations can be plugged into the JNDI interface using the standard service provider interface (SPI) conventions.

JNDI implementation:

  • LDAP (default),
  • NDS,
  • DNS,
  • and NIS.
Advertising

3 - Lookup

Three JNDI namespaces are used for portable JNDI lookups:

  • java:global,
  • java:module,
  • and java:app.

3.1 - global

The java:global JNDI namespace is the portable way of finding remote enterprise beans using JNDI lookups.

JNDI global addresses are of the following form:

java:global[/application name]/module name/enterprise bean name[/interface name]

where:

  • the Default [/application name]/module name is the name of the application and of the module minus the file extension.
  • Application names are required only if the application is packaged within an EAR.
  • The interface name is required only if the enterprise bean implements more than one business interface.

3.2 - module

The java:module namespace is used to look up local enterprise beans within the same module. JNDI addresses using the java:module namespace are of the following form:

java:module/enterprise bean name/[interface name]

where:

  • The interface name is required only if the enterprise bean implements more than one business interface.
Advertising

3.3 - app

The java:app namespace is used to look up local enterprise beans packaged within the same application. That is, the enterprise bean is packaged within an EAR file containing multiple Java EE modules.

JNDI addresses using the java:app namespace are of the following form:

java:app[/module name]/enterprise bean name[/interface name]

where:

  • The module name is optional.
  • The interface name is required only if the enterprise bean implements more than one business interface.

3.4 - Example

For example, if an enterprise bean, MyBean, is packaged within the web application archive myApp.war, the module name is myApp.

The JNDI name using :

  • java:module namespace is java:module/MyBean
  • the java:global namespace is java:global/myApp/MyBean.

4 - Data Source

With JNDI data source, you can take advantage of connection pooling.

5 - Documentation / Reference

Advertising
lang/java/jndi.txt · Last modified: 2019/05/03 14:14 by gerardnico