|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.aop.framework.ProxyConfig org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator
BeanPostProcessor implementation that wraps a group of beans with AOP proxies that delegate to the given interceptors before invoking the bean itself.
This class distinguishes between "common" interceptors: shared for all proxies it creators, 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 autoproxying 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 with any subclass, to create a custom target source--for example, to pool prototype objects. Autoproxying will occur even if there is no advice if a TargetSourceCreator specifies a custom TargetSource. If there are no TargetSourceCreators set, or if none matches, a SingletonTargetSource will be used by default to wrap the bean to be autoproxied.
setInterceptorNames(java.lang.String[])
,
BeanNameAutoProxyCreator
Field Summary | |
protected java.lang.Object[] |
DO_NOT_PROXY
Convenience constant for subclasses: Return value for "do not proxy". |
protected org.apache.commons.logging.Log |
logger
|
protected java.lang.Object[] |
PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
Convenience constant for subclasses: Return value for "proxy without additional interceptors, just the common ones". |
Fields inherited from class org.springframework.aop.framework.ProxyConfig |
exposeProxy |
Constructor Summary | |
AbstractAutoProxyCreator()
|
Method Summary | |
protected BeanFactory |
getBeanFactory()
Return the owning BeanFactory May be null, as this object doesn't need to belong to a bean factory. |
protected abstract java.lang.Object[] |
getInterceptorsAndAdvisorsForBean(java.lang.Object bean,
java.lang.String beanName)
Return whether the given bean is to be proxied, and what additional interceptors and pointcuts to apply. |
int |
getOrder()
Return the order value of this object, higher value meaning greater in terms of sorting. |
protected boolean |
isInfrastructureClass(java.lang.Object bean,
java.lang.String name)
|
java.lang.Object |
postProcessAfterInitialization(java.lang.Object bean,
java.lang.String name)
Create a proxy with the configured interceptors if the bean is identified as one to proxy by the subclass. |
java.lang.Object |
postProcessBeforeInitialization(java.lang.Object bean,
java.lang.String name)
Apply this BeanPostProcessor to the given new bean instance before any bean initialization callbacks (like InitializingBean's afterPropertiesSet or a custom init-method). |
void |
setApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst)
Set whether the common interceptors should be applied before bean-specific ones. |
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance. |
void |
setCustomTargetSourceCreators(java.util.List targetSourceCreators)
Set custom TargetSourceCreators to be applied in this order. |
void |
setInterceptorNames(java.lang.String[] interceptorNames)
Set the common interceptors. |
void |
setOrder(int order)
Set the ordering which will apply to this class's implementation of Ordered, used when applying multiple BeanPostProcessors. |
protected boolean |
shouldSkip(java.lang.Object bean,
java.lang.String name)
Subclasses should override this method to return true if this bean should not be considered for autoproxying by this post processor. |
Methods inherited from class org.springframework.aop.framework.ProxyConfig |
copyFrom, getAopProxyFactory, getExposeProxy, getOptimize, getProxyTargetClass, isFrozen, setAopProxyFactory, setExposeProxy, setFrozen, setOptimize, setProxyTargetClass, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected final java.lang.Object[] DO_NOT_PROXY
getInterceptorsAndAdvisorsForBean(java.lang.Object, java.lang.String)
protected final java.lang.Object[] PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
getInterceptorsAndAdvisorsForBean(java.lang.Object, java.lang.String)
protected final org.apache.commons.logging.Log logger
Constructor Detail |
public AbstractAutoProxyCreator()
Method Detail |
public final void setOrder(int order)
order
- ordering valuepublic final int getOrder()
Ordered
Higher value can be interpreted as lower priority, consequently the first object has highest priority (somewhat analogous to Servlet "load-on-startup" values).
getOrder
in interface Ordered
public void setCustomTargetSourceCreators(java.util.List targetSourceCreators)
TargetSourceCreators can only be invoked if this post processor is used in a BeanFactory, and its BeanFactoryAware callback is used.
targetSourceCreators
- list of TargetSourceCreator.
Ordering is significant: The TargetSource returned from the first matching
TargetSourceCreator (that is, the first that returns non-null) will be used.public void setInterceptorNames(java.lang.String[] interceptorNames)
public void setApplyCommonInterceptorsFirst(boolean applyCommonInterceptorsFirst)
public void setBeanFactory(BeanFactory beanFactory)
BeanFactoryAware
Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method.
setBeanFactory
in interface BeanFactoryAware
beanFactory
- owning BeanFactory (may not be null).
The bean can immediately call methods on the factory.BeanInitializationException
protected BeanFactory getBeanFactory()
public java.lang.Object postProcessBeforeInitialization(java.lang.Object bean, java.lang.String name)
BeanPostProcessor
postProcessBeforeInitialization
in interface BeanPostProcessor
bean
- the new bean instancename
- the name of the bean
public java.lang.Object postProcessAfterInitialization(java.lang.Object bean, java.lang.String name) throws BeansException
postProcessAfterInitialization
in interface BeanPostProcessor
bean
- the new bean instancename
- the name of the bean
BeansException
- in case of errorsgetInterceptorsAndAdvisorsForBean(java.lang.Object, java.lang.String)
protected boolean isInfrastructureClass(java.lang.Object bean, java.lang.String name)
protected boolean shouldSkip(java.lang.Object bean, java.lang.String name)
protected abstract java.lang.Object[] getInterceptorsAndAdvisorsForBean(java.lang.Object bean, java.lang.String beanName) throws BeansException
bean
- the new bean instancebeanName
- the beanName of the bean
BeansException
- in case of errorspostProcessAfterInitialization(java.lang.Object, java.lang.String)
,
DO_NOT_PROXY
,
PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |