1) Introduction
Spring provides support to access objects from the JNDI Repository. This article will begin with the JNDI concepts along with a sample JNDI Application. Then it will proceed with the various core supporting classes available in Spring for JNDI Integration. Following that, practical samples would be given to make things clear. The pre-requisite for this article is some basic introductory knowledge in Spring which can be got by reading the article in javabeat Introduction to Spring Web Framework.
2) JNDI
2.1) Introduction
JNDI stands for Java Naming and Directory interface. It is a specification and API that can be used to access any type directory service. For example, a particular implementation of JNDI specification can be used to access the LDAP Repository. JNDI is used heavily by the J2EE Applications to store Application specific data and business objects.
Imagine the case of a J2EE Application, where it is having a Web module and a EJB Module. A Web module is used to handle the Http Request from the Browser client, process it and then will return the Http Response back to the client. It basically will contain a collection of Servlet components and JSP's. The Web module may use the EJB module for accessing the Enterprise Beans for data manipulation. Suppose, say that we want to store data that is common to both Web and EJB Module. Where we can store this information, in the Web Module or in the EJB Module?. It doesn't make sense to store the data in any of the Modules, because the data is a common data and it is not particularly restricted to any of the Modules.
Here comes the JNDI Repository. The Application Server Container will provide an implementation for the JNDI Repository for storing the global data (data that is common across the modules) and the clients (either the Enterprise Beans, or the Servlets or even the Application client) can use the JNDI API to query the information available in the JNDI Repository. It is also possible to store the Business Objects (like Session Beans, Message Driven beans) in the JNDI Repository. In this case, a Servlet may be the client in getting a reference to the Enterprise Bean from the Repository. It is not necessary for an Application Developer to manually store the Business Objects into the JNDI Repository as the Container will take care of all these things, like constructing the JNDI Tree, storing the Business objects etc.
|