Show TOC

Using Annotations in Web ApplicationsLocate this document in the navigation structure

Use

Overview

The annotations specified by Java EE 5 simplify considerably the development process. They have two major benefits:

  • They can replace the use of deployment descriptors.

    Many of the tags in the deployment descriptors have their analogous annotations (such as <run-as>...</run-as> in the web.xml and the @RunAs annotation). You can configure the behavior of your application using annotations only or a combination between annotations and deployment descriptors.

  • They can replace some of the complex pieces of source code (for example, the @Resource annotation can replace the code fragment for getting a resource from JNDI along with the corresponding tags in the web.xml ).

Annotations are processed during deploy time.

Note

Annotations are not processed in the following cases:

  • The Web application is compliant with J2EE 1.4 or lower

  • The Web application is compliant with Java EE 5 and there is no web.xml

  • The Web application is Java EE 5 and the metadata-complete attribute is set to true in the web.xml

  • Annotation information is set outside the Web application (using references)

  • Annotations information is not from classes placed in WEB-INF/classes or from JAR files placed in WEB-INF/lib

Annotations

More information: Annotations in Web Applications .

Web Components That Can Use Annotations

  • Servlets

  • Filters

  • Listeners

  • Taglib tag handlers

  • JSF managed beans

Procedure

Injecting EJB Resources into Web Applications

More information: Injecting EJB Resources into Web Applications .

Injecting Resources into Web Applications

More information: Injecting Resources into Web Applications .

Accessing Persistence in Web Applications

More information: Accessing Persistence in Web Applications .

Configuring Methods Using Annotations in Web Applications

More information: Configuring Methods Using Annotations in Web Applications .

Configuring Security Roles Using Annotations in Web Applications

More information: Configuring Security Roles Using Annotations in Web Applications .