Download
FAQ History |
API
Search Feedback |
JNDI Naming
In a distributed application, components need to access other components and resources such as databases. For example, a servlet might invoke remote methods on an enterprise bean that retrieves information from a database. In the J2EE platform, the Java Naming and Directory Interface (JNDI) naming service enables components to locate other components and resources. To locate a JDBC resource, for example, an enterprise bean invokes the JNDI
lookup
method. The JNDI naming service maintains a set of bindings that relate names to objects. Thelookup
method passes a JNDI name parameter and returns the related object.JNDI provides a naming context, which is a a set of name-to-object bindings. All naming operations are relative to a context. 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
. AContext
object provides the methods for binding names to objects, unbinding names from objects, renaming objects, and listing the bindings. JNDI also provides subcontext functionality. Much like a directory in a file system, a subcontext is a context within a context. This hierarchical structure permits better organization of information. For naming services that support subcontexts, theContext
class also provides methods for creating and destroying subcontexts.For detailed information about JNDI, see The JNDI Tutorial:
Table 31-1 describes JNDI subcontexts for connection factories in the Sun Java System Application Server Platform Edition 8.
Note: To avoid collisions with names of other enterprise resources in the JNDI namespace, and to avoid portability problems, all names in a J2EE application should begin with the string
java:comp/env
.
Download
FAQ History |
API
Search Feedback |
All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.