JNDI Resources HOW-TO
Table of Contents
Tomcat provides a JNDI InitialContext implementation
instance for each web application running under it, in a manner that is
compatible with those provided by a
Java Enterprise Edition application server. The Java EE standard provides
a standard set of elements in the
/WEB-INF/web.xml file to
See the following Specifications for more information about programming APIs for JNDI, and for the features supported by Java Enterprise Edition (Java EE) servers, which Tomcat emulates for the services that it provides:
The following elements may be used in the web application deployment
/WEB-INF/web.xml) of your web application to define
<env-entry>- Environment entry, a single-value parameter that can be used to configure how the application will operate.
<resource-ref>- Resource reference, which is typically to an object factory for resources such as a JDBC
DataSource, a JavaMail
Session, or custom object factories configured into Tomcat.
<resource-env-ref>- Resource environment reference, a new variation of
resource-refadded in Servlet 2.4 that is simpler to configure for resources that do not require authentication information.
Providing that Tomcat is able to identify an appropriate resource factory to
use to create the resource and that no further configuration information is
required, Tomcat will use the information in
create the resource.
Tomcat provides a number of Tomcat specific options for JNDI resources that
cannot be specified in web.xml. These include
enables faster cleaning-up of JNDI resources when a web application stops and
singleton that controls whether or not a new instance of the
resource is created for every JNDI lookup. To use these configuration options
the resource must be specified in a web application's
<Context> element or in the
<GlobalNamingResources> element of
If Tomcat is unable to identify the appropriate resource factory and/or
additional configuration information is required, additional Tomcat specific
configuration must be specified before Tomcat can create the resource.
Tomcat specific resource configuration is entered in
<Context> elements that
can be specified in either