2.1.1 Scope of support for the annotations included in the javax.annotation package

This section describes the applicability of annotations of the javax.annotation package. The following sections describe the annotations that you can code in each component:

Organization of this subsection
(1) WAR file (Servlet 3.0 compliant)
(2) WAR file (Supported by Servlet 2.5)
(3) EJB-JAR File (EJB3.1/3.0 compliant)
(4) Library JAR file (Servlets or JSPs)
(5) Library JAR file (Enterprise Bean, exception class, or other classes)

(1) WAR file (Servlet 3.0 compliant)

The following table lists the annotations that you can code in a WAR file:

Table 2-1 Annotations (javax.annotation package) that can be coded in WAR file (Servlet 3.0 compliant)

Annotation nameServlet specificationsJSP SpecificationsException ClassManagedBean(JSF)Other class
ServletServlet (API)Servlet filterServlet filter (API)Event listenerEvent listener (API)JSPfileTag handlerTag library event listener
Classic tag handlerSimple tag handler
@PostConstructY--Y--Y----YYN--Y#--
@PreDestroyY--Y--Y----YYN--Y#--
@ResourceY--Y--Y----YYN--Y--
@ResourcesY--Y--Y----YYN--Y--
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not supported by standard specifications.
#
Annotation depends on JSF. For the support scope, see the JSF specification document.

(2) WAR file (Supported by Servlet 2.5)

The following table lists the annotations that you can code in a WAR file.

Table 2-2 Annotations (javax.annotation package) that can be coded in a WAR file (Supported by Servlet 2.5)

Annotation nameServlet specificationsJSP specificationsOther class
ServletServlet filterEvent listenerJSP fileTag handlerTag library event listener
Classic tag handlerSimple tag handler
@PostConstructYYY--YYN--
@PreDestroyYYY--YYN--
@ResourceYYY--YYN--
@ResourcesYYY--YYN--
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.

(3) EJB-JAR File (EJB3.1/3.0 compliant)

The following table lists the annotations that you can code in an EJB-JAR file:

Table 2-3 Annotations (javax.annotation package) that can be coded in an EJB-JAR file (EJB3.1/3.0 compliant)

Annotation nameEnterprise BeanException classOther class
InterfaceSession BeanEntity BeanMessage-driven BeanInterceptor
Other than the default interceptorDefault interceptor
@PostConstruct--Y--NYY----
@PreDestroy--Y--NYY----
@Resource--Y--NYY----
@Resources--Y--NYY----
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.

(4) Library JAR file (Servlets or JSPs)

The following table lists the annotations that you can code in a servlet or a JSP of a library JAR file:

Table 2-4 Annotations (javax.annotation package) that can be coded in a library JAR file (Servlets or JSPs)

Annotation nameServlet specificationsJSP specifications
ServletServlet (API)Servlet filterServlet filter (API)Event listenerEvent listener (API)JSP fileTag handlerTag library event listener
Classic tag handlerSimple tag handler
@PostConstruct----Y--Y----YYN
@PreDestroy----Y--Y----YYN
@Resource----Y--Y----YYN
@Resources----Y--Y----YYN
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.

(5) Library JAR file (Enterprise Bean, exception class, or other classes)

The following table lists the annotations that you can coded in the Enterprise Beans, exception classes, or the other classes of a library JAR file:

Table 2-5 Annotations (javax.annotation package) that can be coded in a library JAR file (Enterprise Beans, exception classes, or other classes)

Annotation nameEnterprise BeanException classOther class
InterfaceSession BeanEntity BeanMessage-driven BeanInterceptor
@PostConstruct------NY----
@PreDestroy------NY----
@Resource------NY----
@Resources------NY----
Legend:
Y: Supported.
N: Not supported by Application Server.
--: Not applicable.