This includes support for the {@link javax.annotation.PostConstruct} and{@link javax.annotation.PreDestroy} annotations (as init annotation and destroyannotation, respectively).
The central element is the {@link javax.annotation.Resource} annotationfor annotation-driven injection of named beans, by default from the containing Spring BeanFactory, with only mappedName
references resolved in JNDI. The {@link #setAlwaysUseJndiLookup "alwaysUseJndiLookup" flag} enforces JNDI lookupsequivalent to standard Java EE 5 resource injection for name
references and default names as well. The target beans can be simple POJOs, with no special requirements other than the type having to match.
The JAX-WS {@link javax.xml.ws.WebServiceRef} annotation is supported too,analogous to {@link javax.annotation.Resource} but with the capability of creatingspecific JAX-WS service endpoints. This may either point to an explicitly defined resource by name or operate on a locally specified JAX-WS service class. Finally, this post-processor also supports the EJB 3 {@link javax.ejb.EJB} annotation,analogous to {@link javax.annotation.Resource} as well, with the capability tospecify both a local bean name and a global JNDI name for fallback retrieval. The target beans can be plain POJOs as well as EJB 3 Session Beans in this case.
The common annotations supported by this post-processor are available in Java 6 (JDK 1.6) as well as in Java EE 5 (which provides a standalone jar for its common annotations as well, allowing for use in any Java 5 based application). Hence, this post-processor works out of the box on JDK 1.6, and requires the JSR-250 API jar (and optionally the JAX-WS API jar and/or the EJB 3 API jar) to be added to the classpath on JDK 1.5 (when running outside of Java EE 5).
For default usage, resolving resource names as Spring bean names, simply define the following in your application context:
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>For direct JNDI access, resolving resource names as JNDI resource references within the Java EE application's "java:comp/env/" namespace, use the following:
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"> <property name="alwaysUseJndiLookup" value="true"/> </bean>Note:
mappedName
references will always be resolved in JNDI, allowing for global JNDI names (including "java:" prefix) as well. The "alwaysUseJndiLookup" flag just affects name
references and default names (inferred from the field name / property name). A default CommonAnnotationBeanPostProcessor will be registered by the "context:annotation-config" and "context:component-scan" XML tags. Remove or turn off the default annotation configuration there if you intend to specify a custom CommonAnnotationBeanPostProcessor bean definition. @author Juergen Hoeller @since 2.5 @see #setAlwaysUseJndiLookup @see #setResourceFactory @see org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor @see org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
|
|