Top Description Fields Constructors Methods
org.springframework.aop.framework

public abstract Class AbstractAdvisingBeanPostProcessor

extends ProxyProcessorSupport
implements SmartInstantiationAwareBeanPostProcessor
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor, org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor, org.springframework.beans.factory.config.BeanPostProcessor
Known Direct Subclasses
org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor
Annotations
@SuppressWarnings:serial
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, org.springframework.aop.Advisor, org.springframework.aop.support.AopUtils, org.springframework.beans.factory.config.BeanPostProcessor, .SmartInstantiationAwareBeanPostProcessor, org.springframework.core.SmartClassLoader, org.springframework.lang.Nullable

Base class for BeanPostProcessor implementations that apply a Spring AOP Advisor to specific beans.
Author
Juergen Hoeller
Since
3.2

Field Summary

Modifier and TypeField and Description
protected Advisor
protected boolean
private final Map<Class<?>, Boolean>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
customizeProxyFactory(ProxyFactory
the ProxyFactory that is already configured with target, advisor and interfaces and will be used to create the proxy immediately after this method returns
proxyFactory
)

Subclasses may choose to implement this: for example, to change the interfaces exposed.

public Class<?>
determineBeanType(Class<?>
the raw class of the bean
beanClass
,
String
the name of the bean
beanName
)

Overrides default org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor.determineBeanType.

Determine the type of the bean to be eventually returned from this processor's postProcessBeforeInstantiation callback.
protected boolean
isEligible(Object
the bean instance
bean
,
String
the name of the bean
beanName
)

Check whether the given bean is eligible for advising with this post-processor's Advisor.

protected boolean
isEligible(Class<?>
the class to check against
targetClass
)

Check whether the given class is eligible for advising with this post-processor's Advisor.

public Object
postProcessAfterInitialization(Object
the new bean instance
bean
,
String
the name of the bean
beanName
)

Overrides default org.springframework.beans.factory.config.BeanPostProcessor.postProcessAfterInitialization.

Apply this BeanPostProcessor to the given new bean instance after any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method).
protected ProxyFactory

Returns:

the ProxyFactory, initialized with this processor's ProxyConfig settings and the specified bean
prepareProxyFactory
(Object
the bean instance to create a proxy for
bean
,
String
the corresponding bean name
beanName
)

Prepare a ProxyFactory for the given bean.

public void
setBeforeExistingAdvisors(boolean beforeExistingAdvisors)

Set whether this post-processor's advisor is supposed to apply before existing advisors when encountering a pre-advised object.

Inherited from org.springframework.aop.framework.ProxyProcessorSupport:
evaluateProxyInterfacesgetOrdergetProxyClassLoaderisConfigurationCallbackInterfaceisInternalLanguageInterfacesetBeanClassLoadersetOrdersetProxyClassLoader

Field Detail

advisorback to summary
protected Advisor advisor
Annotations
@Nullable
beforeExistingAdvisorsback to summary
protected boolean beforeExistingAdvisors
eligibleBeansback to summary
private final Map<Class<?>, Boolean> eligibleBeans

Constructor Detail

AbstractAdvisingBeanPostProcessorback to summary
public AbstractAdvisingBeanPostProcessor()

Method Detail

customizeProxyFactoryback to summary
protected void customizeProxyFactory(ProxyFactory proxyFactory)

Subclasses may choose to implement this: for example, to change the interfaces exposed.

The default implementation is empty.

Parameters
proxyFactory:ProxyFactory

the ProxyFactory that is already configured with target, advisor and interfaces and will be used to create the proxy immediately after this method returns

Since
4.2.3
See Also
prepareProxyFactory
determineBeanTypeback to summary
public Class<?> determineBeanType(Class<?> beanClass, String beanName)

Overrides default org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor.determineBeanType.

Doc from org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor.determineBeanType.

Determine the type of the bean to be eventually returned from this processor's postProcessBeforeInstantiation callback.

The default implementation returns the given bean class as-is. Specific implementations should fully evaluate their processing steps in order to create/initialize a potential proxy class upfront.

Parameters
beanClass:Class<?>

the raw class of the bean

beanName:String

the name of the bean

Returns:Class<?>

the type of the bean (never null)

Annotations
@Override
isEligibleback to summary
protected boolean isEligible(Object bean, String beanName)

Check whether the given bean is eligible for advising with this post-processor's Advisor.

Delegates to isEligible(Class) for target class checking. Can be overridden e.g. to specifically exclude certain beans by name.

Note

Only called for regular bean instances but not for existing proxy instances which implement Advised and allow for adding the local Advisor to the existing proxy's Advisor chain. For the latter, isEligible(Class) is being called directly, with the actual target class behind the existing proxy (as determined by AopUtils#getTargetClass(Object)).

Parameters
bean:Object

the bean instance

beanName:String

the name of the bean

See Also
isEligible(Class)
isEligibleback to summary
protected boolean isEligible(Class<?> targetClass)

Check whether the given class is eligible for advising with this post-processor's Advisor.

Implements caching of canApply results per bean target class.

Parameters
targetClass:Class<?>

the class to check against

See Also
AopUtils#canApply(Advisor, Class)
postProcessAfterInitializationback to summary
public Object postProcessAfterInitialization(Object bean, String beanName)

Overrides default org.springframework.beans.factory.config.BeanPostProcessor.postProcessAfterInitialization.

Doc from org.springframework.beans.factory.config.BeanPostProcessor.postProcessAfterInitialization.

Apply this BeanPostProcessor to the given new bean instance after any bean initialization callbacks (like InitializingBean's afterPropertiesSet 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 method, in contrast to all other BeanPostProcessor callbacks.

The default implementation returns the given bean as-is.

Parameters
bean:Object

the new bean instance

beanName:String

the name of the bean

Returns:Object

the bean instance to use, either the original or a wrapped one; if null, no subsequent BeanPostProcessors will be invoked

Annotations
@Override
prepareProxyFactoryback to summary
protected ProxyFactory prepareProxyFactory(Object bean, String beanName)

Prepare a ProxyFactory for the given bean.

Subclasses may customize the handling of the target instance and in particular the exposure of the target class. The default introspection of interfaces for non-target-class proxies and the configured advisor will be applied afterwards; customizeProxyFactory allows for late customizations of those parts right before proxy creation.

Parameters
bean:Object

the bean instance to create a proxy for

beanName:String

the corresponding bean name

Returns:ProxyFactory

the ProxyFactory, initialized with this processor's ProxyConfig settings and the specified bean

Since
4.2.3
See Also
customizeProxyFactory
setBeforeExistingAdvisorsback to summary
public void setBeforeExistingAdvisors(boolean beforeExistingAdvisors)

Set whether this post-processor's advisor is supposed to apply before existing advisors when encountering a pre-advised object.

Default is "false", applying the advisor after existing advisors, i.e. as close as possible to the target method. Switch this to "true" in order for this post-processor's advisor to wrap existing advisors as well.

Note

Check the concrete post-processor's javadoc whether it possibly changes this flag by default, depending on the nature of its advisor.