Resource environment providers

 

+

Search Tips   |   Advanced Search

 

The java:comp/env environment provides a single mechanism by which both JNDI name space objects and local application environment objects can be searched. WAS provides a number of local environment entries by default.

The J2EE 1.4 specification also provides a mechanism for defining custom, non-default, environment entries using <resource-env-ref> entries defined in an application's standard deployment descriptors. The specification separates the definition of the resource environment entry from the application by: - Requiring the appserver to provide a mechanism for defining separate administrative objects that encapsulate a resource environment entry. The administrative objects are accessible through JNDI in the appserver's local name space, java:comp/env. The specification does not define how an appserver should provide this functionality. As a result, the mechanism is generally application-server product-specific. - Specifying the administrative object's JNDI lookup name and the expected returned object type in the <resource-env-ref>.

Example 6-5 shows a resource environment entry defined in an application's Web module deployment descriptor, web.xml.

<web-app>
.....
<resource-env-ref>
  <resource-env-ref-name>myapp/MyLogWriter</resource-env-ref-name>
  <resource-env-ref-type>com.ibm.itso.test.LogWriter</resource-env-ref-type>
</resource-env-ref>
.....
</web-app>

Example 6-6 shows how this resource environment entry could be accessed from Java code in the Web module.

import com.ibm.itso.test.*;
.....
InitialContext ctx = new InitialContext();
LogWriter myLog = (LogWriter) ctx.lookup("java:comp/env/myapp/MyLogWriter");
myLog.write(msg);
.....

Next