Adding annotations to a Web application

Java™ EE 5 supports the injection of annotations into your source code, so that you can embed resources, dependencies, services, and life-cycle notifications in your source code, without having to maintain these artifacts elsewhere. Annotations simplify the development and configuration of enterprise applications.

You can add annotations into your source code by adding the annotation directly in the Java editor or by using the Annotations view. For information on adding annotations to your source code, refer to Adding annotations.

Table 1. Annotations supported by Java EE 5 Web applications
Annotation type Annotation Description
Common annotations @Resource The Resource annotation declares a reference to a resource that is required by the application.
@Resources The Resources annotation declares multiple resources declarations.
@DeclaresRoles The DeclaresRoles annotation specifies the security roles for the application.
@RunAs The RunAs annotation specifies the role of the application during runtime.
@PostConstruct The PostConstruct annotation specifies the container that will invoke after resource injection is complete to perform any initialization.
@PreDestroy The PreDestroy annotation is used to signal that the instance is in being removed by the container.
EJBs @PersistenceContext The PersistenceContext annotation specifies the container managed entity context.
@PersistenceContexts The PersistenceContexts annotation declares multiple @PersistenceContext annotations.
@PersistenceUnit The PersistenceUnit annotation specifies a reference to an entity manager factory for use with EJBs.
@PersistenceUnits The PersistenceUnits annotation declares multiple @PersistenceUnit annotations.
Web services @WebServiceRef The WebServiceRef annotation specifies a reference to a Web service within a Web application.
@WebServicesRefs The WebServicesRefs annotation declare multiple @WebServiceRef annotations.

For more information about Web tier resource injection, refer to: