Class AbstractAdvisingBeanPostProcessor
- All Implemented Interfaces:
Serializable,AopInfrastructureBean,Aware,BeanClassLoaderAware,BeanPostProcessor,InstantiationAwareBeanPostProcessor,SmartInstantiationAwareBeanPostProcessor,Ordered
- Direct Known Subclasses:
AbstractBeanFactoryAwareAdvisingPostProcessor
BeanPostProcessor implementations that apply a
Spring AOP Advisor to specific beans.- Since:
- 3.2
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
FieldsFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcustomizeProxyFactory(ProxyFactory proxyFactory) Subclasses may choose to implement this: for example, to change the interfaces exposed.Class<?>determineBeanType(Class<?> beanClass, String beanName) Determine the type of the bean to be eventually returned from this processor'sInstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)callback.protected booleanisEligible(Class<?> targetClass) Check whether the given class is eligible for advising with this post-processor'sAdvisor.protected booleanisEligible(Object bean, String beanName) Check whether the given bean is eligible for advising with this post-processor'sAdvisor.postProcessAfterInitialization(Object bean, String beanName) Apply thisBeanPostProcessorto the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method).protected ProxyFactoryprepareProxyFactory(Object bean, String beanName) Prepare aProxyFactoryfor the given bean.voidsetBeforeExistingAdvisors(boolean beforeExistingAdvisors) Set whether this post-processor's advisor is supposed to apply before existing advisors when encountering a pre-advised object.Methods inherited from class org.springframework.aop.framework.ProxyProcessorSupport
evaluateProxyInterfaces, getOrder, getProxyClassLoader, isConfigurationCallbackInterface, isInternalLanguageInterface, setBeanClassLoader, setOrder, setProxyClassLoaderMethods inherited from class org.springframework.aop.framework.ProxyConfig
copyFrom, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setExposeProxy, setFrozen, setOpaque, setOptimize, setProxyTargetClass, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessBeforeInitializationMethods inherited from interface org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
postProcessAfterInstantiation, postProcessBeforeInstantiation, postProcessPropertiesMethods inherited from interface org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
determineCandidateConstructors, getEarlyBeanReference, predictBeanType
-
Field Details
-
advisor
-
beforeExistingAdvisors
protected boolean beforeExistingAdvisors
-
-
Constructor Details
-
AbstractAdvisingBeanPostProcessor
public AbstractAdvisingBeanPostProcessor()
-
-
Method Details
-
setBeforeExistingAdvisors
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.
-
determineBeanType
Description copied from interface:SmartInstantiationAwareBeanPostProcessorDetermine 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 the given bean class as-is. Specific implementations should fully evaluate their processing steps in order to create/initialize a potential proxy class upfront.
- Specified by:
determineBeanTypein interfaceSmartInstantiationAwareBeanPostProcessor- Parameters:
beanClass- the raw class of the beanbeanName- the name of the bean- Returns:
- the type of the bean (never
null)
-
postProcessAfterInitialization
Description copied from interface:BeanPostProcessorApply thisBeanPostProcessorto the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSetor 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 FactoryBeanchecks.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 otherBeanPostProcessorcallbacks.The default implementation returns the given
beanas-is.- Specified by:
postProcessAfterInitializationin 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 - See Also:
-
isEligible
Check whether the given bean is eligible for advising with this post-processor'sAdvisor.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
Advisedand allow for adding the localAdvisorto the existing proxy'sAdvisorchain. For the latter,isEligible(Class)is being called directly, with the actual target class behind the existing proxy (as determined byAopUtils.getTargetClass(Object)).- Parameters:
bean- the bean instancebeanName- the name of the bean- See Also:
-
isEligible
Check whether the given class is eligible for advising with this post-processor'sAdvisor.Implements caching of
canApplyresults per bean target class.- Parameters:
targetClass- the class to check against- See Also:
-
prepareProxyFactory
Prepare aProxyFactoryfor 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.- Parameters:
bean- the bean instance to create a proxy forbeanName- the corresponding bean name- Returns:
- the ProxyFactory, initialized with this processor's
ProxyConfigsettings and the specified bean - Since:
- 4.2.3
- See Also:
-
customizeProxyFactory
Subclasses may choose to implement this: for example, to change the interfaces exposed.The default implementation is empty.
- Parameters:
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:
-