Sitemap

Member-only story

Java Naming and Directory Interface

--

JNDI

What is JNDI?

JNDI (Java Naming and Directory Interface) is an API in Java that provides naming and directory functionality, enabling Java applications to discover and access resources in a distributed system. It allows applications to look up objects by a name in a directory service (e.g., a JNDI registry) and retrieve those objects for use.

Why is JNDI Used?

JNDI serves several purposes in enterprise Java applications:

  1. Resource Discovery: It enables applications to discover resources (e.g., DataSources, EJBs, Mail Sessions) in a distributed environment.
  2. Decoupling: By allowing the application to look up resources at runtime, it decouples the resource configurations from the application code, making the system more flexible and easier to manage.
  3. Interoperability: It supports integration with multiple directory services like LDAP, DNS, NIS, and RMI registries.
  4. Centralized Configuration: JNDI allows administrators to define and manage resources centrally, simplifying deployment and configuration.

Practical Examples of JNDI

  1. Database Connection Pooling: JNDI is commonly used to look up a DataSource for database connections in Java EE applications.

--

--