You can declare the characteristics of resources
to be returned for JNDI lookups of <resource-ref>
and
<resource-env-ref>
elements in the web application
deployment descriptor by defining them in this element and then linking
them with <ResourceLink>
elements
in the <Context>
element.
You MUST also define any other needed parameters using
attributes on the Resource element, to configure
the object factory to be used (if not known to Tomcat already), and
the properties used to configure that object factory.
For example, you can create a resource definition like this:
<GlobalNamingResources ...>
...
<Resource name="jdbc/EmployeeDB" auth="Container"
type="javax.sql.DataSource"
description="Employees Database for HR Applications"/>
...
</GlobalNamingResources>
This is equivalent to the inclusion of the following element in the
web application deployment descriptor (/WEB-INF/web.xml
):
<resource-ref>
<description>Employees Database for HR Applications</description>
<res-ref-name>jdbc/EmployeeDB</res-ref-name>
<res-ref-type>javax.sql.DataSource</res-ref-type>
<res-auth>Container</res-auth>
</resource-ref>
but does not require modification of the deployment
descriptor to customize this value.
The valid attributes for a <Resource>
element
are as follows:
Attribute | Description |
---|
auth |
Specify whether the web Application code signs on to the
corresponding resource manager programmatically, or whether the
Container will sign on to the resource manager on behalf of the
application. The value of this attribute must be
Application or Container . This
attribute is required if the web application
will use a <resource-ref> element in the web
application deployment descriptor, but is optional if the
application uses a <resource-env-ref> instead.
|
closeMethod |
Name of the zero-argument method to call on a singleton resource when
it is no longer required. This is intended to speed up clean-up of
resources that would otherwise happen as part of garbage collection.
This attribute is ignored if the singleton attribute is
false. If not specified, no default is defined and no close method will
be called.
For Apache Commons DBCP 1.x and Apache Tomcat JDBC connection pools
you can use closeMethod="close" .
|
description |
Optional, human-readable description of this resource.
|
name |
The name of the resource to be created, relative to the
java:comp/env context.
|
scope |
Specify whether connections obtained through this resource
manager can be shared. The value of this attribute must be
Shareable or Unshareable . By default,
connections are assumed to be shareable.
|
singleton |
Specify whether this resource definition is for a singleton resource,
i.e. one where there is only a single instance of the resource. If this
attribute is true , multiple JNDI lookups for this resource
will return the same object. If this attribute is false ,
multiple JNDI lookups for this resource will return different objects.
This attribute must be true for
javax.sql.DataSource r |