public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSupport implements BeanPostProcessor
BeanPostProcessor
implementations that apply a
Spring AOP Advisor
to specific beans.Modifier and Type | Field and Description |
---|---|
protected Advisor |
advisor |
protected boolean |
beforeExistingAdvisors |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
AbstractAdvisingBeanPostProcessor() |
Modifier and Type | Method and Description |
---|---|
protected void |
customizeProxyFactory(ProxyFactory proxyFactory)
Subclasses may choose to implement this: for example,
to change the interfaces exposed.
|
protected boolean |
isEligible(Class<?> targetClass)
Check whether the given class is eligible for advising with this
post-processor's
Advisor . |
protected boolean |
isEligible(Object bean,
String beanName)
Check whether the given bean is eligible for advising with this
post-processor's
Advisor . |
Object |
postProcessAfterInitialization(Object bean,
String beanName)
Apply this BeanPostProcessor to the given new bean instance after any bean
initialization callbacks (like InitializingBean's
afterPropertiesSet
or a custom init-method). |
Object |
postProcessBeforeInitialization(Object bean,
String beanName)
Apply this BeanPostProcessor to the given new bean instance before any bean
initialization callbacks (like InitializingBean's
afterPropertiesSet
or a custom init-method). |
protected ProxyFactory |
prepareProxyFactory(Object bean,
String beanName)
Prepare a
ProxyFactory for the given bean. |
void |
setBeforeExistingAdvisors(boolean beforeExistingAdvisors)
Set whether this post-processor's advisor is supposed to apply before
existing advisors when encountering a pre-advised object.
|
evaluateProxyInterfaces, getOrder, getProxyClassLoader, isConfigurationCallbackInterface, isInternalLanguageInterface, setBeanClassLoader, setOrder, setProxyClassLoader
copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toString
protected Advisor advisor
protected boolean beforeExistingAdvisors
public void setBeforeExistingAdvisors(boolean beforeExistingAdvisors)
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.
public Object postProcessBeforeInitialization(Object bean, String beanName)
BeanPostProcessor
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.postProcessBeforeInitialization
in interface BeanPostProcessor
bean
- the new bean instancebeanName
- the name of the beannull
, no subsequent BeanPostProcessors will be invokedInitializingBean.afterPropertiesSet()
public Object postProcessAfterInitialization(Object bean, String beanName)
BeanPostProcessor
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(java.lang.Class<?>, java.lang.String)
method,
in contrast to all other BeanPostProcessor callbacks.
postProcessAfterInitialization
in interface BeanPostProcessor
bean
- the new bean instancebeanName
- the name of the beannull
, no subsequent BeanPostProcessors will be invokedInitializingBean.afterPropertiesSet()
,
FactoryBean
protected boolean isEligible(Object bean, String beanName)
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)
).
bean
- the bean instancebeanName
- the name of the beanisEligible(Class)
protected boolean isEligible(Class<?> targetClass)
Advisor
.
Implements caching of canApply
results per bean target class.
targetClass
- the class to check againstAopUtils.canApply(Advisor, Class)
protected ProxyFactory prepareProxyFactory(Object bean, String beanName)
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(org.springframework.aop.framework.ProxyFactory)
allows for
late customizations of those parts right before proxy creation.
bean
- the bean instance to create a proxy forbeanName
- the corresponding bean nameProxyConfig
settings and the specified beancustomizeProxyFactory(org.springframework.aop.framework.ProxyFactory)
protected void customizeProxyFactory(ProxyFactory proxyFactory)
The default implementation is empty.
proxyFactory
- ProxyFactory that is already configured with
target, advisor and interfaces and will be used to create the proxy
immediately after this method returnsprepareProxyFactory(java.lang.Object, java.lang.String)