Using Annotations in Web Applications

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.

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 .