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

RequiredAnnotationBeanPostProcessor

open class RequiredAnnotationBeanPostProcessor : InstantiationAwareBeanPostProcessorAdapter, MergedBeanDefinitionPostProcessor, PriorityOrdered, BeanFactoryAware

org.springframework.beans.factory.config.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.

Author
Rob Harrop

Author
Juergen Hoeller

Since
2.0

See Also
#setRequiredAnnotationTypeRequired

Constructors

<init>

RequiredAnnotationBeanPostProcessor()

org.springframework.beans.factory.config.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.

Properties

SKIP_REQUIRED_CHECK_ATTRIBUTE

static val SKIP_REQUIRED_CHECK_ATTRIBUTE: String

Bean definition attribute that may indicate whether a given bean is supposed to be skipped when performing this post-processor's required property check.

Functions

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

setBeanFactory

open fun setBeanFactory(beanFactory: BeanFactory): Unit

setOrder

open fun setOrder(order: Int): Unit

setRequiredAnnotationType

open fun setRequiredAnnotationType(requiredAnnotationType: Class<out Annotation>): Unit

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.

Inherited Functions

determineCandidateConstructors

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

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<*>