| java.lang.Object org.springframework.aop.framework.ProxyConfig org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
All known Subclasses: org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator, org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator,
AbstractAutoProxyCreator | abstract public class AbstractAutoProxyCreator extends ProxyConfig implements InstantiationAwareBeanPostProcessor,BeanClassLoaderAware,BeanFactoryAware,Ordered,AopInfrastructureBean(Code) | | org.springframework.beans.factory.config.BeanPostProcessor implementation
that wraps each eligible bean with an AOP proxy, delegating to specified interceptors
before invoking the bean itself.
This class distinguishes between "common" interceptors: shared for all proxies it
creates, and "specific" interceptors: unique per bean instance. There need not
be any common interceptors. If there are, they are set using the interceptorNames
property. As with ProxyFactoryBean, interceptors names in the current factory
are used rather than bean references to allow correct handling of prototype
advisors and interceptors: for example, to support stateful mixins.
Any advice type is supported for "interceptorNames" entries.
Such auto-proxying is particularly useful if there's a large number of beans that
need to be wrapped with similar proxies, i.e. delegating to the same interceptors.
Instead of x repetitive proxy definitions for x target beans, you can register
one single such post processor with the bean factory to achieve the same effect.
Subclasses can apply any strategy to decide if a bean is to be proxied,
e.g. by type, by name, by definition details, etc. They can also return
additional interceptors that should just be applied to the specific bean
instance. The default concrete implementation is BeanNameAutoProxyCreator,
identifying the beans to be proxied via a list of bean names.
Any number of
TargetSourceCreator implementations can be used to create
a custom target source - for example, to pool prototype objects. Auto-proxying will
occur even if there is no advice, as long as a TargetSourceCreator specifies a custom
org.springframework.aop.TargetSource . If there are no TargetSourceCreators set,
or if none matches, a
org.springframework.aop.target.SingletonTargetSource will be used by default to wrap the target bean instance.
author: Juergen Hoeller author: Rod Johnson author: Rob Harrop since: 13.10.2003 See Also: AbstractAutoProxyCreator.setInterceptorNames See Also: AbstractAutoProxyCreator.getAdvicesAndAdvisorsForBean See Also: BeanNameAutoProxyCreator See Also: DefaultAdvisorAutoProxyCreator |
Field Summary | |
final protected static Object[] | DO_NOT_PROXY Convenience constant for subclasses: Return value for "do not proxy". | final protected static Object[] | PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS Convenience constant for subclasses: Return value for
"proxy without additional interceptors, just the common ones". | final protected Log | logger |
Method Summary | |
protected Advisor[] | buildAdvisors(String beanName, Object[] specificInterceptors) Determine the advisors for the given bean, including the specific interceptors
as well as the common interceptor, all adapted to the Advisor interface. | protected Object | createProxy(Class beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) Create an AOP proxy for the given bean. | protected void | customizeProxyFactory(ProxyFactory proxyFactory) Subclasses may choose to implement this: for example,
to change the interfaces exposed. | abstract protected Object[] | getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, TargetSource customTargetSource) Return whether the given bean is to be proxied, what additional
advices (e.g. | protected BeanFactory | getBeanFactory() Return the owning BeanFactory
May be null , as this object doesn't need to belong to a bean factory. | protected Object | getCacheKey(Class beanClass, String beanName) Build a cache key for the given bean class and bean name. | protected TargetSource | getCustomTargetSource(Class beanClass, String beanName) Create a target source for bean instances. | final public int | getOrder() | public boolean | isFrozen() | protected boolean | isInfrastructureClass(Class beanClass, String beanName) Return whether the given bean class and bean name represents an
infrastructure class that should never be proxied. | protected boolean | isInfrastructureClass(Class beanClass) Return whether the given bean class represents an infrastructure class
that should never be proxied. | public Object | postProcessAfterInitialization(Object bean, String beanName) Create a proxy with the configured interceptors if the bean is
identified as one to proxy by the subclass. | public boolean | postProcessAfterInstantiation(Object bean, String beanName) | public Object | postProcessBeforeInitialization(Object bean, String beanName) | public Object | postProcessBeforeInstantiation(Class beanClass, String beanName) | public PropertyValues | postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) | public void | setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) Specify the AdvisorAdapterRegistry to use. | public void | setApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst) Set whether the common interceptors should be applied before bean-specific ones. | public void | setBeanClassLoader(ClassLoader classLoader) | public void | setBeanFactory(BeanFactory beanFactory) | public void | setCustomTargetSourceCreators(TargetSourceCreator[] targetSourceCreators) Set custom TargetSourceCreators to be applied in this order.
If the list is empty, or they all return null, a SingletonTargetSource
will be created for each bean.
Note that TargetSourceCreators will kick in even for target beans
where no advices or advisors have been found. | public void | setFrozen(boolean frozen) Set whether or not the proxy should be frozen, preventing advice
from being added to it once it is created. | public void | setInterceptorNames(String[] interceptorNames) Set the common interceptors. | final public void | setOrder(int order) Set the ordering which will apply to this class's implementation
of Ordered, used when applying multiple BeanPostProcessors. | protected boolean | shouldProxyTargetClass(Class beanClass, String beanName) Determine whether the given bean should be proxied with its target
class rather than its interfaces. | protected boolean | shouldSkip(Class beanClass, String beanName) Subclasses should override this method to return true if the
given bean should not be considered for auto-proxying by this post-processor.
Sometimes we need to be able to avoid this happening if it will lead to
a circular reference. |
logger | final protected Log logger(Code) | | Logger available to subclasses
|
buildAdvisors | protected Advisor[] buildAdvisors(String beanName, Object[] specificInterceptors)(Code) | | Determine the advisors for the given bean, including the specific interceptors
as well as the common interceptor, all adapted to the Advisor interface.
Parameters: beanName - the name of the bean Parameters: specificInterceptors - the set of interceptors that isspecific to this bean (may be empty, but not null) the list of Advisors for the given bean |
createProxy | protected Object createProxy(Class beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource)(Code) | | Create an AOP proxy for the given bean.
Parameters: beanClass - the class of the bean Parameters: beanName - the name of the bean Parameters: specificInterceptors - the set of interceptors that isspecific to this bean (may be empty, but not null) Parameters: targetSource - the TargetSource for the proxy,already pre-configured to access the bean the AOP proxy for the bean See Also: AbstractAutoProxyCreator.buildAdvisors |
customizeProxyFactory | protected void customizeProxyFactory(ProxyFactory proxyFactory)(Code) | | Subclasses may choose to implement this: for example,
to change the interfaces exposed.
The default implementation is empty.
Parameters: proxyFactory - ProxyFactory that is already configured withTargetSource and interfaces and will be used to create the proxyimmediably after this method returns |
getBeanFactory | protected BeanFactory getBeanFactory()(Code) | | Return the owning BeanFactory
May be null , as this object doesn't need to belong to a bean factory.
|
getCacheKey | protected Object getCacheKey(Class beanClass, String beanName)(Code) | | Build a cache key for the given bean class and bean name.
Parameters: beanClass - the bean class Parameters: beanName - the bean name the cache key for the given class and name |
getCustomTargetSource | protected TargetSource getCustomTargetSource(Class beanClass, String beanName)(Code) | | Create a target source for bean instances. Uses any TargetSourceCreators if set.
Returns null if no custom TargetSource should be used.
This implementation uses the "customTargetSourceCreators" property.
Subclasses can override this method to use a different mechanism.
Parameters: beanClass - the class of the bean to create a TargetSource for Parameters: beanName - the name of the bean a TargetSource for this bean See Also: AbstractAutoProxyCreator.setCustomTargetSourceCreators |
getOrder | final public int getOrder()(Code) | | |
isFrozen | public boolean isFrozen()(Code) | | |
isInfrastructureClass | protected boolean isInfrastructureClass(Class beanClass)(Code) | | Return whether the given bean class represents an infrastructure class
that should never be proxied.
Default implementation considers Advisors, Advices and
AbstractAutoProxyCreators as infrastructure classes.
Parameters: beanClass - the class of the bean whether the bean represents an infrastructure class See Also: org.springframework.aop.Advisor See Also: org.aopalliance.intercept.MethodInterceptor See Also: AbstractAutoProxyCreator.shouldSkip |
postProcessAfterInstantiation | public boolean postProcessAfterInstantiation(Object bean, String beanName)(Code) | | |
setApplyCommonInterceptorsFirst | public void setApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst)(Code) | | Set whether the common interceptors should be applied before bean-specific ones.
Default is "true"; else, bean-specific interceptors will get applied first.
|
setCustomTargetSourceCreators | public void setCustomTargetSourceCreators(TargetSourceCreator[] targetSourceCreators)(Code) | | Set custom TargetSourceCreators to be applied in this order.
If the list is empty, or they all return null, a SingletonTargetSource
will be created for each bean.
Note that TargetSourceCreators will kick in even for target beans
where no advices or advisors have been found. If a TargetSourceCreator
returns a TargetSource for a specific bean, that bean will be proxied
in any case.
TargetSourceCreators can only be invoked if this post processor is used
in a BeanFactory, and its BeanFactoryAware callback is used.
Parameters: targetSourceCreators - list of TargetSourceCreator.Ordering is significant: The TargetSource returned from the first matchingTargetSourceCreator (that is, the first that returns non-null) will be used. |
setFrozen | public void setFrozen(boolean frozen)(Code) | | Set whether or not the proxy should be frozen, preventing advice
from being added to it once it is created.
Overridden from the super class to prevent the proxy configuration
from being frozen before the proxy is created.
|
setInterceptorNames | public void setInterceptorNames(String[] interceptorNames)(Code) | | Set the common interceptors. These must be bean names in the current factory.
They can be of any advice or advisor type Spring supports.
If this property isn't set, there will be zero common interceptors.
This is perfectly valid, if "specific" interceptors such as matching
Advisors are all we want.
|
setOrder | final public void setOrder(int order)(Code) | | Set the ordering which will apply to this class's implementation
of Ordered, used when applying multiple BeanPostProcessors.
Default value is Integer.MAX_VALUE , meaning that it's non-ordered.
Parameters: order - ordering value |
shouldSkip | protected boolean shouldSkip(Class beanClass, String beanName)(Code) | | Subclasses should override this method to return true if the
given bean should not be considered for auto-proxying by this post-processor.
Sometimes we need to be able to avoid this happening if it will lead to
a circular reference. This implementation returns false .
Parameters: beanClass - the class of the bean Parameters: beanName - the name of the bean whether to skip the given bean |
|
|