Top Description Methods
org.springframework.beans.factory.config

public Interface InstantiationAwareBeanPostProcessor

extends BeanPostProcessor
Known Direct Subinterfaces
org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
Imports
org.springframework.beans.BeansException, .PropertyValues, org.springframework.lang.Nullable

Subinterface of BeanPostProcessor 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.

Authors
Juergen Hoeller, Rod Johnson
Since
1.2
See Also
org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#setCustomTargetSourceCreators, org.springframework.aop.framework.autoproxy.target.LazyInitTargetSourceCreator

Method Summary

Modifier and TypeMethod and Description
public default boolean

Returns:

true if properties should be set on the bean; false if property population should be skipped. Normal implementations should return true. Returning false will also prevent any subsequent InstantiationAwareBeanPostProcessor instances being invoked on this bean instance.
postProcessAfterInstantiation
(Object
the bean instance created, with properties not having been set yet
bean
,
String
the name of the bean
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.

public default Object

Returns:

the bean object to expose instead of a default instance of the target bean, or null to proceed with default instantiation
postProcessBeforeInstantiation
(Class<?>
the class of the bean to be instantiated
beanClass
,
String
the name of the bean
beanName
)

Apply this BeanPostProcessor before the target bean gets instantiated.

public default PropertyValues

Returns:

the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or null to skip property population
postProcessProperties
(PropertyValues
the property values that the factory is about to apply (never null)
pvs
,
Object
the bean instance created, but whose properties have not yet been set
bean
,
String
the name of the bean
beanName
)

Post-process the given property values before the factory applies them to the given bean.

Inherited from org.springframework.beans.factory.config.BeanPostProcessor:
postProcessAfterInitializationpostProcessBeforeInitialization

Method Detail

postProcessAfterInstantiationback to summary
public 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.

Parameters
bean:Object

the bean instance created, with properties not having been set yet

beanName:String

the name of the bean

Returns:boolean

true if properties should be set on the bean; false if property population should be skipped. Normal implementations should return true. Returning false will also prevent any subsequent InstantiationAwareBeanPostProcessor instances being invoked on this bean instance.

Exceptions
BeansException:
in case of errors
See Also
postProcessBeforeInstantiation
postProcessBeforeInstantiationback to summary
public 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 postProcessAfterInitialization callback from the configured BeanPostProcessors.

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.

Parameters
beanClass:Class<?>

the class of the bean to be instantiated

beanName:String

the name of the bean

Returns:Object

the bean object to expose instead of a default instance of the target bean, or null to proceed with default instantiation

Annotations
@Nullable
Exceptions
BeansException:
in case of errors
See Also
postProcessAfterInstantiation, org.springframework.beans.factory.support.AbstractBeanDefinition#getBeanClass(), org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName()
postProcessPropertiesback to summary
public 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.

The default implementation returns the given pvs as-is.

Parameters
pvs:PropertyValues

the property values that the factory is about to apply (never null)

bean:Object

the bean instance created, but whose properties have not yet been set

beanName:String

the name of the bean

Returns:PropertyValues

the actual property values to apply to the given bean (can be the passed-in PropertyValues instance), or null to skip property population

Annotations
@Nullable
Exceptions
BeansException:
in case of errors
Since
5.1