org.springframework.beans.factory.config.BeanPostProcessor implementation
that autowires annotated fields, setter methods and arbitrary config methods.
Such members to be injected are detected through a Java 5 annotation:
by default, Spring's Autowired annotation.
Only one constructor (at max) of any given bean class may carry this
annotation with the 'required' parameter set to true,
indicating the constructor to autowire when used as a Spring bean.
If multiple non-required constructors carry the annotation, they
will be considered as candidates for autowiring. The constructor with
the greatest number of dependencies that can be satisfied by matching
beans in the Spring container will be chosen. If none of the candidates
can be satisfied, then a default constructor (if present) will be used.
An annotated constructor does not have to be public.
Fields are injected right after construction of a bean, before any config methods are invoked. Such a config field does not have to be public.
Config methods may have an arbitrary name and any number of arguments; each of those arguments will be autowired with a matching bean in the Spring container. Bean property setter methods are effectively just a special case of such a general config method. Such config methods do not have to be public.
Also supports JSR-330's annotation, if available.
javax.inject.Inject
Note: A default AutowiredAnnotationBeanPostProcessor 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 AutowiredAnnotationBeanPostProcessor 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.
setAutowiredAnnotationType(java.lang.Class)Autowiredpublic classAutowiredAnnotationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter
Autowired annotation.
Also supports JSR-330's annotation, if available.
javax.inject.Inject
this.autowiredAnnotationTypes.add((Class<? extends Annotation>) cl.loadClass("javax.inject.Inject"));
The default autowired annotation type is the Spring-provided
annotation, as well as Autowired.
Value
This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a member is supposed to be autowired.
The default autowired annotation type is the Spring-provided
annotation, as well as Autowired.
Value
This setter property exists so that developers can provide their own (non-Spring-specific) annotation types to indicate that a member is supposed to be autowired.
public voidsetAutowiredAnnotationTypes(Set<Class<? extends Annotation>> autowiredAnnotationTypes) {
setRequiredParameterValue(boolean)public voidpostProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) {
public Constructor[]determineCandidateConstructors(Class beanClass, String beanName) throws BeansException {
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
@Autowired.
bean the target instance to processorg.springframework.beans.BeansException if autowiring failedthrow new BeanCreationException("Injection of autowired dependencies failed for class [" + clazz + "]", ex);
LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
type the type of the beanorg.springframework.beans.BeansException if bean retrieval failedA 'required' dependency means that autowiring should fail when no beans are found. Otherwise, the autowiring process will simply bypass the field or method when no beans are found.
annotation the Autowired annotationMethod method = ReflectionUtils.findMethod(annotation.annotationType(), this.requiredParameterName);
return (this.requiredParameterValue == (Boolean) ReflectionUtils.invokeMethod(method, annotation));