spring-framework / org.springframework.beans.factory.annotation / AutowiredAnnotationBeanPostProcessor

AutowiredAnnotationBeanPostProcessor

open class AutowiredAnnotationBeanPostProcessor : InstantiationAwareBeanPostProcessorAdapter, MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware

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 and Value annotations.

Also supports JSR-330's javax.inject.Inject annotation, if available, as a direct alternative to Spring's own @Autowired.

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. Config methods do not have to be public.

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.

In addition to regular injection points as discussed above, this post-processor also handles Spring's Lookup annotation which identifies lookup methods to be replaced by the container at runtime. This is essentially a type-safe version of getBean(Class, args) and getBean(String, args), See Lookup for details.

Author
Juergen Hoeller

Author
Mark Fisher

Author
Stephane Nicoll

Author
Sebastien Deleuze

Since
2.5

See Also
#setAutowiredAnnotationTypeAutowiredValue

Constructors

<init>

AutowiredAnnotationBeanPostProcessor()

Create a new AutowiredAnnotationBeanPostProcessor for Spring's standard Autowired annotation.

Also supports JSR-330's javax.inject.Inject annotation, if available.

Functions

determineCandidateConstructors

open fun determineCandidateConstructors(beanClass: Class<*>, beanName: String): Array<Constructor<*>>

getOrder

open fun getOrder(): Int

postProcessMergedBeanDefinition

open fun postProcessMergedBeanDefinition(beanDefinition: RootBeanDefinition, beanType: Class<*>, beanName: String): Unit

postProcessPropertyValues

open fun postProcessPropertyValues(pvs: PropertyValues, pds: Array<PropertyDescriptor>, bean: Any, beanName: String): PropertyValues

processInjection

open fun processInjection(bean: Any): Unit

'Native' processing method for direct calls with an arbitrary target instance, resolving all of its fields and methods which are annotated with @Autowired.

setAutowiredAnnotationType

open fun setAutowiredAnnotationType(autowiredAnnotationType: Class<out Annotation>): Unit

Set the 'autowired' annotation type, to be used on constructors, fields, setter methods and arbitrary config methods.

The default autowired annotation type is the Spring-provided Autowired annotation, as well as 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.

setAutowiredAnnotationTypes

open fun setAutowiredAnnotationTypes(autowiredAnnotationTypes: MutableSet<Class<out Annotation>>): Unit

Set the 'autowired' annotation types, to be used on constructors, fields, setter methods and arbitrary config methods.

The default autowired annotation type is the Spring-provided Autowired annotation, as well as 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.

setBeanFactory

open fun setBeanFactory(beanFactory: BeanFactory): Unit

setOrder

open fun setOrder(order: Int): Unit

setRequiredParameterName

open fun setRequiredParameterName(requiredParameterName: String): Unit

Set the name of a parameter of the annotation that specifies whether it is required.

setRequiredParameterValue

open fun setRequiredParameterValue(requiredParameterValue: Boolean): Unit

Set the boolean value that marks a dependency as required

For example if using 'required=true' (the default), this value should be true; but if using 'optional=false', this value should be false.

Inherited Functions

getEarlyBeanReference

open fun getEarlyBeanReference(bean: Any, beanName: String): Any

postProcessAfterInitialization

open fun postProcessAfterInitialization(bean: Any, beanName: String): Any

postProcessAfterInstantiation

open fun postProcessAfterInstantiation(bean: Any, beanName: String): Boolean

postProcessBeforeInitialization

open fun postProcessBeforeInitialization(bean: Any, beanName: String): Any

postProcessBeforeInstantiation

open fun postProcessBeforeInstantiation(beanClass: Class<*>, beanName: String): Any

predictBeanType

open fun predictBeanType(beanClass: Class<*>, beanName: String): Class<*>