Class InstantiationAwareBeanPostProcessorAdapter
- java.lang.Object
- org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter
- All Implemented Interfaces:
BeanPostProcessor
,InstantiationAwareBeanPostProcessor
,SmartInstantiationAwareBeanPostProcessor
- Direct Known Subclasses:
AutowiredAnnotationBeanPostProcessor
,RequiredAnnotationBeanPostProcessor
,ScriptFactoryPostProcessor
public abstract class InstantiationAwareBeanPostProcessorAdapter extends Object implements SmartInstantiationAwareBeanPostProcessor
Adapter that implements all methods onSmartInstantiationAwareBeanPostProcessor
as no-ops, which will not change normal processing of each bean instantiated by the container. Subclasses may override merely those methods that they are actually interested in.Note that this base class is only recommendable if you actually require
InstantiationAwareBeanPostProcessor
functionality. If all you need is plainBeanPostProcessor
functionality, prefer a straight implementation of that (simpler) interface.- Since:
- 2.0
- Author:
- Rod Johnson, Juergen Hoeller
Constructor Summary
Constructors Constructor Description InstantiationAwareBeanPostProcessorAdapter()
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Constructor<?>[]
determineCandidateConstructors(Class<?> beanClass, String beanName)
Determine the candidate constructors to use for the given bean.Object
getEarlyBeanReference(Object bean, String beanName)
Obtain a reference for early access to the specified bean, typically for the purpose of resolving a circular reference.Object
postProcessAfterInitialization(Object bean, String beanName)
Apply thisBeanPostProcessor
to the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSet
or a custom init-method).boolean
postProcessAfterInstantiation(Object bean, String beanName)
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.Object
postProcessBeforeInitialization(Object bean, String beanName)
Apply thisBeanPostProcessor
to the given new bean instance before any bean initialization callbacks (like InitializingBean'safterPropertiesSet
or a custom init-method).Object
postProcessBeforeInstantiation(Class<?> beanClass, String beanName)
Apply this BeanPostProcessor before the target bean gets instantiated.PropertyValues
postProcessProperties(PropertyValues pvs, Object bean, String beanName)
Post-process the given property values before the factory applies them to the given bean, without any need for property descriptors.PropertyValues
postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
Deprecated.Class<?>
predictBeanType(Class<?> beanClass, String beanName)
Predict the type of the bean to be eventually returned from this processor'sInstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)
callback.
Constructor Detail
InstantiationAwareBeanPostProcessorAdapter
public InstantiationAwareBeanPostProcessorAdapter()
Method Detail
predictBeanType
@Nullable public Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException
Description copied from interface:SmartInstantiationAwareBeanPostProcessor
Predict the type of the bean to be eventually returned from this processor'sInstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)
callback.The default implementation returns
null
.- Specified by:
predictBeanType
in interfaceSmartInstantiationAwareBeanPostProcessor
- Parameters:
beanClass
- the raw class of the beanbeanName
- the name of the bean- Returns:
- the type of the bean, or
null
if not predictable - Throws:
BeansException
- in case of errors
determineCandidateConstructors
@Nullable public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException
Description copied from interface:SmartInstantiationAwareBeanPostProcessor
Determine the candidate constructors to use for the given bean.The default implementation returns
null
.- Specified by:
determineCandidateConstructors
in interfaceSmartInstantiationAwareBeanPostProcessor
- Parameters:
beanClass
- the raw class of the bean (nevernull
)beanName
- the name of the bean- Returns:
- the candidate constructors, or
null
if none specified - Throws:
BeansException
- in case of errors
getEarlyBeanReference
public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException
Description copied from interface:SmartInstantiationAwareBeanPostProcessor
Obtain a reference for early access to the specified bean, typically for the purpose of resolving a circular reference.This callback gives post-processors a chance to expose a wrapper early - that is, before the target bean instance is fully initialized. The exposed object should be equivalent to the what
BeanPostProcessor.postProcessBeforeInitialization(java.lang.Object, java.lang.String)
/BeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)
would expose otherwise. Note that the object returned by this method will be used as bean reference unless the post-processor returns a different wrapper from said post-process callbacks. In other words: Those post-process callbacks may either eventually expose the same reference or alternatively return the raw bean instance from those subsequent callbacks (if the wrapper for the affected bean has been built for a call to this method already, it will be exposes as final bean reference by default).The default implementation returns the given
bean
as-is.- Specified by:
getEarlyBeanReference
in interfaceSmartInstantiationAwareBeanPostProcessor
- Parameters:
bean
- the raw bean instancebeanName
- the name of the bean- Returns:
- the object to expose as bean reference (typically with the passed-in bean instance as default)
- Throws:
BeansException
- in case of errors
postProcessBeforeInstantiation
@Nullable public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException
Description copied from interface:InstantiationAwareBeanPostProcessor
Apply this BeanPostProcessor before the target bean gets instantiated. The returned bean object may be a proxy to use instead of the target bean, effectively suppressing default instantiation of the target bean.If a non-null object is returned by this method, the bean creation process will be short-circuited. The only further processing applied is the
BeanPostProcessor.postProcessAfterInitialization(java.lang.Object, java.lang.String)
callback from the configuredBeanPostProcessors
.This callback will be applied to bean definitions with their bean class, as well as to factory-method definitions in which case the returned bean type will be passed in here.
Post-processors may implement the extended
SmartInstantiationAwareBeanPostProcessor
interface in order to predict the type of the bean object that they are going to return here.The default implementation returns
null
.- Specified by:
postProcessBeforeInstantiation
in interfaceInstantiationAwareBeanPostProcessor
- Parameters:
beanClass
- the class of the bean to be instantiatedbeanName
- the name of the bean- Returns:
- the bean object to expose instead of a default instance of the target bean, or
null
to proceed with default instantiation - Throws:
BeansException
- in case of errors- See Also:
InstantiationAwareBeanPostProcessor.postProcessAfterInstantiation(java.lang.Object, java.lang.String)
,AbstractBeanDefinition.getBeanClass()
,AbstractBeanDefinition.getFactoryMethodName()
postProcessAfterInstantiation
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException
Description copied from interface:InstantiationAwareBeanPostProcessor
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.This is the ideal callback for performing custom field injection on the given bean instance, right before Spring's autowiring kicks in.
The default implementation returns
true
.- Specified by:
postProcessAfterInstantiation
in interfaceInstantiationAwareBeanPostProcessor
- Parameters:
bean
- the bean instance created, with properties not having been set yetbeanName
- the name of the bean- Returns:
true
if properties should be set on the bean;false
if property population should be skipped. Normal implementations should returntrue
. Returningfalse
will also prevent any subsequent InstantiationAwareBeanPostProcessor instances being invoked on this bean instance.- Throws:
BeansException
- in case of errors- See Also:
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)
postProcessProperties
public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException
Description copied from interface:InstantiationAwareBeanPostProcessor
Post-process the given property values before the factory applies them to the given bean, without any need for property descriptors.Implementations should return
null
(the default) if they provide a customInstantiationAwareBeanPostProcessor.postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
implementation, andpvs
otherwise. In a future version of this interface (withInstantiationAwareBeanPostProcessor.postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
removed), the default implementation will return the givenpvs
as-is directly.- Specified by:
postProcessProperties
in interfaceInstantiationAwareBeanPostProcessor
- Parameters:
pvs
- the property values that the factory is about to apply (nevernull
)bean
- the bean instance created, but whose properties have not yet been setbeanName
- the name of the bean- Returns:
- the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or
null
which proceeds with the existing properties but specifically continues with a call toInstantiationAwareBeanPostProcessor.postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
(requiring initializedPropertyDescriptor
s for the current bean class) - Throws:
BeansException
- in case of errors- See Also:
InstantiationAwareBeanPostProcessor.postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
postProcessPropertyValues
@Deprecated public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException
Deprecated.Description copied from interface:InstantiationAwareBeanPostProcessor
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.
The default implementation returns the given
pvs
as-is.- Specified by:
postProcessPropertyValues
in interfaceInstantiationAwareBeanPostProcessor
- Parameters:
pvs
- the property values that the factory is about to apply (nevernull
)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 setbeanName
- the name of the bean- Returns:
- the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or
null
to skip property population - Throws:
BeansException
- in case of errors- See Also:
InstantiationAwareBeanPostProcessor.postProcessProperties(org.springframework.beans.PropertyValues, java.lang.Object, java.lang.String)
,MutablePropertyValues
postProcessBeforeInitialization
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
Description copied from interface:BeanPostProcessor
Apply thisBeanPostProcessor
to the given new bean instance before any bean initialization callbacks (like InitializingBean'safterPropertiesSet
or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.The default implementation returns the given
bean
as-is.- Specified by:
postProcessBeforeInitialization
in interfaceBeanPostProcessor
- Parameters:
bean
- the new bean instancebeanName
- the name of the bean- Returns:
- the bean instance to use, either the original or a wrapped one; if
null
, no subsequent BeanPostProcessors will be invoked - Throws:
BeansException
- in case of errors- See Also:
InitializingBean.afterPropertiesSet()
postProcessAfterInitialization
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
Description copied from interface:BeanPostProcessor
Apply thisBeanPostProcessor
to the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSet
or a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.In case of a FactoryBean, this callback will be invoked for both the FactoryBean instance and the objects created by the FactoryBean (as of Spring 2.0). The post-processor can decide whether to apply to either the FactoryBean or created objects or both through corresponding
bean instanceof FactoryBean
checks.This callback will also be invoked after a short-circuiting triggered by a
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)
method, in contrast to all otherBeanPostProcessor
callbacks.The default implementation returns the given
bean
as-is.- Specified by:
postProcessAfterInitialization
in interfaceBeanPostProcessor
- Parameters:
bean
- the new bean instancebeanName
- the name of the bean- Returns:
- the bean instance to use, either the original or a wrapped one; if
null
, no subsequent BeanPostProcessors will be invoked - Throws:
BeansException
- in case of errors- See Also:
InitializingBean.afterPropertiesSet()
,FactoryBean