7-4 Developing Applications for Oracle WebLogic Server
■
Section 7.3.4, javax.annotation.Resources For detailed information about EJB-specific annotations for WebLogic Server
Enterprise JavaBeans, see Programming WebLogic Enterprise JavaBeans, Version 3.0 for Oracle WebLogic Server.
For detailed information about web component-specific annotations WebLogic Server applications, see WebLogic Annotation for Web Components in Developing Web
Applications, Servlets, and JSPs for Oracle WebLogic Server.
7.3.1 javax.annotation.PostConstruct
Target: Method
Specifies the life cycle callback method that the application component should execute before the first business method invocation and after dependency injection is done to
perform any initialization. This method will be called after all injections have occurred and before the class is put into service. This method will be called even if the class
doesnt request any resources to be injected.
You must specify a PostConstruct method in any component that includes dependency injection.
Only one method in the component can be annotated with this annotation. The method annotated with PostConstruct must follow these requirements:
■
The method must not have any parameters, except in the case of EJB interceptors, in which case it takes an
javax.interceptor.InvocationContext object as defined by the EJB specification.
■
The return type of the method must be void.
■
The method must not throw a checked exception.
■
The method may be public, protected, package private or private.
■
The method must not be static except for the application client.
■
The method may be final or non-final, except in the case of EJBs where it must be non-final.
■
If the method throws an unchecked exception the class must not be put into service. In the case of EJBs, the method
annotated with PostConstruct can handle exceptions and cleanup before the bean instance is discarded.
This annotation does not have any attributes.
7.3.2 javax.annotation.PreDestroy
Target:
Method Specifies the life cycle callback method that signals that the application component is
about to be destroyed by the container. You typically apply this annotation to methods that release resources that the class has been holding.
Only one method in the bean class can be annotated with this annotation. The method annotated with PreDestroy must follow these requirements:
■
The method must not have any parameters, except in the case of EJB interceptors, in which case it takes an
Using Java EE Annotations and Dependency Injection 7-5
javax.interceptor.InvocationContext object as defined by the EJB specification.
■
The return type of the method must be void.
■
The method must not throw a checked exception.
■
The method may be public, protected, package private or private.
■
The method must not be static except for the application client.
■
The method may be final or non-final, except in the case of EJBs where it must be non-final.
■
If the method throws an unchecked exception the class must not be put into service. In the case of EJBs, the method
annotated with PreDestroy can handle exceptions and cleanup before the bean instance is discarded.
This annotation does not have any attributes.
7.3.3 javax.annotation.Resource