Web Component Classes That Support Annotations

8 WebLogic Annotation for Web Components 8-1 8 WebLogic Annotation for Web Components The following sections describe how to annotate Web components. ■ Section 8.1, Servlet Annotation and Dependency Injection ■ Section 8.2, Annotating Servlets

8.1 Servlet Annotation and Dependency Injection

With Java EE metadata annotations, the standard web.xml deployment descriptor is now optional. The Servlet 2.5 specification see http:java.sun.comproductsservletindex.jsp states annotations can be defined on certain Web components, such as servlets, filters, listeners, and tag handlers. The annotations are used to declare dependencies on external resources. The container will detect annotations on such components and inject necessary dependencies before the components life cycle methods are invoked. Dependency Injection DI will only be done on certain components, as described in Section 8.1.1, Web Component Classes That Support Annotations . Annotation processing and DI will be performed on all Web applications that have the version set to 2.5. However, annotation processing is expensive and it can increase the deployment time for Web applications depending on the size of the included classes. Set the metadata-complete attribute to true in the web.xml descriptor if your Web application does not have any annotations and if you have the version set to 2.5 to avoid unnecessary scanning of the Web applications classes for annotations. Alternatively, you can turn off annotation processing and DI for all the Web applications by setting -Dweblogic.servlet.DIDisabled=true flag when starting WebLogic Server. For more information about using Java EE annotations and dependency injection with WebLogic Server applications, see Using Java EE Annotations and Dependency Injection in Developing Applications for Oracle WebLogic Server. For detailed information about EJB-specific annotations for WebLogic Server Enterprise JavaBeans, see Programming WebLogic Enterprise JavaBeans, Version 3.0 for Oracle WebLogic Server.

8.1.1 Web Component Classes That Support Annotations

This section describes the behavior of annotations and dependency injection DI of resources in a Java EE compliant Web container. The Web container only processes annotations for the types of classes listed in Table 8–1 . 8-2 Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server The Web container will not process annotations on classes like Java Beans and other helper classes. The Web container follows these steps to achieve DI: 1. Annotation Processing—The Web container processes annotations during the Web application deployment phase. As annotations are processed, the container figures out the relevant entries in the descriptor that get affected by the annotation and update the descriptor tree. The Servlet 2.5 specification at http:java.sun.comproductsservletindex.jsp indicates that all annotations can be declared in the descriptor by defining an injection target. The Web container updates the descriptor tree with the injection targets so that as deployment continues the java:compenv tree is updated with the necessary entries. 2. Dependency Injection DI—DI is done when instances are created for the types listed in Table 8–1 . For listeners and filters, this occurs during the deployment phase, and for servlets it can occur during the deployment or run time.

8.1.2 Annotations Supported By a Web Container