java.lang.Object | ||
↳ | org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter | |
↳ | org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor |
BeanPostProcessor
implementation
that enforces required JavaBean properties to have been configured.
Required bean properties are detected through a Java 5 annotation:
by default, Spring's Required
annotation.
The motivation for the existence of this BeanPostProcessor is to allow developers to annotate the setter properties of their own classes with an arbitrary JDK 1.5 annotation to indicate that the container must check for the configuration of a dependency injected value. This neatly pushes responsibility for such checking onto the container (where it arguably belongs), and obviates the need (in part) for a developer to code a method that simply checks that all required properties have actually been set.
Please note that an 'init' method may still need to implemented (and may
still be desirable), because all that this class does is enforce that a
'required' property has actually been configured with a value. It does
not check anything else... In particular, it does not check that a
configured value is not null
.
Note: A default RequiredAnnotationBeanPostProcessor 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 RequiredAnnotationBeanPostProcessor bean definition.
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.springframework.core.Ordered
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
SKIP_REQUIRED_CHECK_ATTRIBUTE | Bean definition attribute that may indicate whether a given bean is supposed to be skipped when performing this post-processor's required property check. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the order value of this object, with a
higher value meaning greater in terms of sorting.
| |||||||||||
Post-process the given property values before the factory applies them
to the given bean.
| |||||||||||
Callback that supplies the owning factory to a bean instance.
| |||||||||||
Set the 'required' annotation type, to be used on bean property
setter methods.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return the 'required' annotation type.
| |||||||||||
Is the supplied property required to have a value (that is, to be dependency-injected)?
This implementation looks for the existence of a
| |||||||||||
Check whether the given bean definition is not subject to the annotation-based
required property check as performed by this post-processor.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanFactoryAware
| |||||||||||
From interface
org.springframework.beans.factory.config.BeanPostProcessor
| |||||||||||
From interface
org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
| |||||||||||
From interface
org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
| |||||||||||
From interface
org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
| |||||||||||
From interface
org.springframework.core.Ordered
|
Bean definition attribute that may indicate whether a given bean is supposed to be skipped when performing this post-processor's required property check.
Return the order value of this object, with a higher value meaning greater in terms of sorting.
Normally starting with 0, with Integer.MAX_VALUE
indicating the greatest value. Same order values will result
in arbitrary positions for the affected objects.
Higher values can be interpreted as lower priority. As a consequence, the object with the lowest value has highest priority (somewhat analogous to Servlet "load-on-startup" values).
Post-process the given property values before the factory applies them to the given bean. Allows for checking whether all dependencies have been satisfied, for example based on a "Required" annotation on bean property setters.
Also allows for replacing the property values to apply, typically through creating a new MutablePropertyValues instance based on the original PropertyValues, adding or removing specific values.
pvs | the property values that the factory is about to apply (never null ) |
---|---|
pds | the relevant property descriptors for the target bean (with ignored dependency types - which the factory handles specifically - already filtered out) |
bean | the bean instance created, but whose properties have not yet been set |
beanName | the name of the bean |
null
to skip property populationBeansException |
---|
Callback that supplies the owning factory to a bean instance.
Invoked after the population of normal bean properties
but before an initialization callback such as
afterPropertiesSet()
or a custom init-method.
beanFactory | owning BeanFactory (never null ).
The bean can immediately call methods on the factory. |
---|
Set the 'required' annotation type, to be used on bean property setter methods.
The default required annotation type is the Spring-provided
Required
annotation.
This setter property exists so that developers can provide their own (non-Spring-specific) annotation type to indicate that a property value is required.
Return the 'required' annotation type.
Is the supplied property required to have a value (that is, to be dependency-injected)?
This implementation looks for the existence of a
"required" annotation
on the supplied property
.
propertyDescriptor | the target PropertyDescriptor (never null ) |
---|
true
if the supplied property has been marked as being required;
false
if not, or if the supplied property does not have a setter method
Check whether the given bean definition is not subject to the annotation-based required property check as performed by this post-processor.
The default implementations check for the presence of the
SKIP_REQUIRED_CHECK_ATTRIBUTE
attribute in the bean definition, if any.
beanFactory | the BeanFactory to check against |
---|---|
beanName | the name of the bean to check against |
true
to skip the bean; false
to process it