org.springframework.beans.factory.config.BeanPostProcessor implementation
that supports common Java annotations out of the box, in particular the common
annotations in the jakarta.annotation package. These common Java
annotations are supported in many Jakarta EE technologies (e.g. JSF and JAX-RS).
This post-processor includes support for the jakarta.
and jakarta. annotations - as init annotation
and destroy annotation, respectively - through inheriting from
InitDestroyAnnotationBeanPostProcessor with pre-configured annotation types.
The central element is the jakarta. annotation
for annotation-driven injection of named beans, by default from the containing
Spring BeanFactory, with only mappedName references resolved in JNDI.
The "alwaysUseJndiLookup" flag enforces JNDI lookups
equivalent to standard Jakarta EE 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.
Additionally, the original javax.annotation variants of the annotations
dating back to the JSR-250 specification (Java EE 5-8, also included in JDK 6-8)
are still supported as well. Note that this is primarily for a smooth upgrade path,
not for adoption in new applications.
This post-processor also supports the EJB jakarta. annotation,
analogous to jakarta., with the capability to
specify both a local bean name and a global JNDI name for fallback retrieval.
The target beans can be plain POJOs as well as EJB Session Beans in this case.
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 Jakarta EE application's "java:comp/env/" namespace, use the following:
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"> <property name="alwaysUseJndiLookup" value="true"/> </bean>
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).Note
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!
Note
Annotation injection will be performed before XML injection; thus the latter configuration will override the former for properties wired through both approaches.
setAlwaysUseJndiLookup, setResourceFactory, org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor , org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
| Modifier and Type | Class and Description |
|---|---|
| private static class | CommonAnnotationBeanPostProcessor.
|
| private class | CommonAnnotationBeanPostProcessor.
Class representing injection information about an annotated field or setter method, supporting the @EJB annotation. |
| private class | CommonAnnotationBeanPostProcessor.
Class representing injection information about an annotated field or setter method, supporting the @Resource annotation. |
| protected abstract static class | CommonAnnotationBeanPostProcessor.
Class representing generic injection information about an annotated field or setter method, supporting @Resource and related annotations. |
| private class | CommonAnnotationBeanPostProcessor.
Class representing injection information about an annotated field or setter method, supporting the @Resource annotation. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private transient BeanFactory | |
| private static final Class | |
| private transient StringValueResolver | |
| private boolean | |
| private final Set | |
| private final transient Map | |
| private static final Class | |
| private static final Class | |
| private transient BeanFactory | |
| private static final boolean | |
| private static final Set | |
| private transient BeanFactory |
| Access | Constructor and Description |
|---|---|
| public | CommonAnnotationBeanPostProcessor()
Create a new CommonAnnotationBeanPostProcessor,
with the init and destroy annotation types set to
|
| Modifier and Type | Method and Description |
|---|---|
| protected Object | Returns: the resource object (nevernull)the factory to autowire against factory, CommonAnnotationBeanPostProcessor.the descriptor for the annotated field/method element,the name of the requesting bean requestingBeanName)Obtain a resource object for the given name and type through autowiring based on the given factory. |
| protected Object | Returns: the resource object (nevernull)the descriptor for the annotated field/method element,the name of the requesting bean requestingBeanName)Obtain a lazily resolving resource proxy for the given name and type,
delegating to |
| private InjectionMetadata | |
| private InjectionMetadata | |
| private AutowireCandidateResolver | |
| private Collection | |
| protected Object | Returns: the resource object (nevernull)the descriptor for the annotated field/method element,the name of the requesting bean requestingBeanName)Obtain the resource object for the given name and type. |
| public void | ignoreResourceType(String
the resource type to ignore resourceType)Ignore the given resource type when resolving |
| private static Class | |
| public boolean | postProcessAfterInstantiation(Object
the bean instance created, with properties not having been set yet bean, String the name of the bean beanName)Overrides default org. Perform operations after the bean has been instantiated, via a constructor or factory method, but before Spring property population (from explicit properties or autowiring) occurs. |
| public Object | postProcessBeforeInstantiation(Class<?>
the class of the bean to be instantiated beanClass, String the name of the bean beanName)Overrides default org. Apply this BeanPostProcessor before the target bean gets instantiated. |
| public void | postProcessMergedBeanDefinition(RootBeanDefinition
the merged bean definition for the bean beanDefinition, Class<?> the actual type of the managed bean instance beanType, String the name of the bean beanName)
Implements org. Post-process the given merged bean definition for the specified bean. |
| public PropertyValues | postProcessProperties(PropertyValues
the property values that the factory is about to apply (never pvs, Object null)the bean instance created, but whose properties have not yet been set bean, String the name of the bean beanName)Overrides default org. Post-process the given property values before the factory applies them to the given bean. |
| public BeanRegistrationAotContribution | processAheadOfTime(RegisteredBean
the registered bean to process registeredBean)
Implements org. Process the given |
| public void | processInjection(Object
the target instance to process bean)Native processing method for direct calls with an arbitrary target instance, resolving all of its fields and methods which are annotated with one of the supported 'resource' annotation types. |
| public void | resetBeanDefinition(String
the name of the bean beanName)Overrides default org. A notification that the bean definition for the specified name has been reset, and that this post-processor should clear any metadata for the affected bean. |
| public void | setAlwaysUseJndiLookup(boolean alwaysUseJndiLookup)
Set whether to always use JNDI lookups equivalent to standard Jakarta EE resource
injection, even for |
| public void | setBeanFactory(BeanFactory
owning BeanFactory (never beanFactory)null).
The bean can immediately call methods on the factory.Implements org. Callback that supplies the owning factory to a bean instance. |
| public void | setFallbackToDefaultTypeMatch(boolean fallbackToDefaultTypeMatch)
Set whether to allow a fallback to a type match if no explicit name has been specified. |
| public void | setJndiFactory(BeanFactory jndiFactory)
Specify the factory for objects to be injected into |
| public void | setResourceFactory(BeanFactory resourceFactory)
Specify the factory for objects to be injected into |