接口 InstantiationAwareBeanPostProcessor
- 所有超级接口:
BeanPostProcessor
- 所有已知实现类:
AbstractAdvisorAutoProxyCreator
,AbstractAutoProxyCreator
,AnnotationAwareAspectJAutoProxyCreator
,AspectJAwareAdvisorAutoProxyCreator
,AutowiredAnnotationBeanPostProcessor
,BeanNameAutoProxyCreator
,CommonAnnotationBeanPostProcessor
,DefaultAdvisorAutoProxyCreator
,InfrastructureAdvisorAutoProxyCreator
,InstantiationAwareBeanPostProcessorAdapter
,PersistenceAnnotationBeanPostProcessor
,RequiredAnnotationBeanPostProcessor
,ScriptFactoryPostProcessor
public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor
Subinterface ofBeanPostProcessor
that adds a before-instantiation callback, and a callback after instantiation but before explicit properties are set or autowiring occurs.Typically used to suppress default instantiation for specific target beans, for example to create proxies with special TargetSources (pooling targets, lazily initializing targets, etc), or to implement additional injection strategies such as field injection.
NOTE: This interface is a special purpose interface, mainly for internal use within the framework. It is recommended to implement the plain
BeanPostProcessor
interface as far as possible, or to derive fromInstantiationAwareBeanPostProcessorAdapter
in order to be shielded from extensions to this interface.- 从以下版本开始:
- 1.2
- 作者:
- Juergen Hoeller, Rod Johnson
- 另请参阅:
AbstractAutoProxyCreator.setCustomTargetSourceCreators(org.springframework.aop.framework.autoproxy.TargetSourceCreator...)
,LazyInitTargetSourceCreator
方法概要
所有方法 实例方法 默认方法 已过时的方法 修饰符和类型 方法 说明 default 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.default Object
postProcessBeforeInstantiation(Class<?> beanClass, String beanName)
Apply this BeanPostProcessor before the target bean gets instantiated.default 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.default PropertyValues
postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
已过时。as of 5.1, in favor ofpostProcessProperties(PropertyValues, Object, String)
从接口继承的方法 org.springframework.beans.factory.config.BeanPostProcessor
postProcessAfterInitialization, postProcessBeforeInitialization
方法详细资料
postProcessBeforeInstantiation
@Nullable default Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException
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
.- 参数:
beanClass
- the class of the bean to be instantiatedbeanName
- the name of the bean- 返回:
- the bean object to expose instead of a default instance of the target bean, or
null
to proceed with default instantiation - 抛出:
BeansException
- in case of errors- 另请参阅:
postProcessAfterInstantiation(java.lang.Object, java.lang.String)
,AbstractBeanDefinition.getBeanClass()
,AbstractBeanDefinition.getFactoryMethodName()
postProcessAfterInstantiation
default boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException
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
.- 参数:
bean
- the bean instance created, with properties not having been set yetbeanName
- the name of the bean- 返回:
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.- 抛出:
BeansException
- in case of errors- 另请参阅:
postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)
postProcessProperties
@Nullable default PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException
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 custompostProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
implementation, andpvs
otherwise. In a future version of this interface (withpostProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
removed), the default implementation will return the givenpvs
as-is directly.- 参数:
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- 返回:
- 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 topostProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
(requiring initializedPropertyDescriptor
s for the current bean class) - 抛出:
BeansException
- in case of errors- 从以下版本开始:
- 5.1
- 另请参阅:
postProcessPropertyValues(org.springframework.beans.PropertyValues, java.beans.PropertyDescriptor[], java.lang.Object, java.lang.String)
postProcessPropertyValues
@Deprecated @Nullable default PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException
已过时。as of 5.1, in favor ofpostProcessProperties(PropertyValues, Object, String)
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.- 参数:
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- 返回:
- the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or
null
to skip property population - 抛出:
BeansException
- in case of errors- 另请参阅:
postProcessProperties(org.springframework.beans.PropertyValues, java.lang.Object, java.lang.String)
,MutablePropertyValues