Servlet 2.5 Annotations and Resource Injections
The 2.5 Servlet Specification adds the ability to inject JNDI resources into fields and methods of servlets, filters and listeners, and also to perform certain callbacks at various points in the lifecycle of a web application.
JNDI resource injection and the lifecycle callbacks can be specified entirely within the web.xml file, or alternatively marked up as
annotations in your source code. You can even use a combination of annotations and web.xml declarations.
First, lets look at how to use web.xml for injections and callbacks.
Resource Injections and Callbacks specified in web.xml
The Servlet 2.5 schema has been augmented to support the declaration of resource injection and lifecycle callbacks.
Here is a small example of the injection of a DataSource resource:
This example shows that the resource named
java:comp/env/jdbc/mydatasource will be injected by Jetty into the the field named
myDatasource or the method named
setMyDatasource(javax.sql.DataSource) in the instance of the class
com.acme.JNDITest before it goes into service.
PAGE UNDER CONSTRUCTION.