Monday, 29 March 2010

Java EE 5 Annotations and Resource Injection in some container managed components

The Annotations that are required by a Java EE technology compliant web container:


Annotations
@DeclareRoles (*)
@RunAs (*)
@EJB
@EJBs
@Resource
@Resources
@PersistenceContext
@PersistenceContexts
@PersistenceUnit
@PersistenceUnits
@PostConstruct
@PreDestroy
@WebServiceRef
@WebServiceRefs



Annotations must be supported on the following container managed classes that implement the following interfaces:

Component Type
Component Type Classes implementing the following interfaces

Notes
Servlets
javax.servlet.Servlet

Java Servlet Specification version 2.5

References must be injected prior to any lifecycle methods being called and the component instance being made available the application.

Filters
javax.servlet.Filter

Listeners
javax.servlet.ServletContextAttributeListener
javax.servlet.ServletRequestListener
javax.servlet.ServletRequestAttributeListener
javax.servlet.http.HttpSessionListener
javax.servlet.http.HttpSessionAttributeListener
javax.servlet.AsyncListener

ManagedBean
JavaServer Faces Specification v 2.0

Only beans declared to be in request, session, or application scope are eligible for resource injection.

Methods on managed beans declared to be in request, view, session, or application scope, annotated with @PostConstruct, must be called by the JSF implementation after resource injection is performed (if any) but before the bean is placed into scope.

Methods on managed beans declared to be in request, session, or application scope, annotated with @PreDestroy, must be called by the JSF implementation before the bean is removed from its scope or before the scope itself is destroyed, whichever comes first. In the case of a managed bean placed in view scope, methods annotated with @PreDestroy must only be called when the view scope is destroyed.



(*) Annotations not allowed in Managed Bean


No comments:

Post a Comment