java.lang.Object | ||
↳ | org.springframework.aop.framework.ProxyConfig | |
↳ | org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator |
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.
setInterceptorNames(String[])
getAdvicesAndAdvisorsForBean(Class, String, TargetSource)
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
org.springframework.core.Ordered
|
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DO_NOT_PROXY | Convenience constant for subclasses: Return value for "do not proxy". | ||||||||||
PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS | Convenience constant for subclasses: Return value for "proxy without additional interceptors, just the common ones". | ||||||||||
logger | Logger available to subclasses |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a proxy with the configured interceptors if the bean is identified as one to proxy by the subclass.
| |||||||||||
Specify the AdvisorAdapterRegistry to use.
| |||||||||||
Set whether the common interceptors should be applied before bean-specific ones.
| |||||||||||
Set custom TargetSourceCreators to be applied in this order.
| |||||||||||
Set whether or not the proxy should be frozen, preventing advice from being added to it once it is created.
| |||||||||||
Set the common interceptors.
| |||||||||||
Set the ordering which will apply to this class's implementation of Ordered, used when applying multiple
BeanPostProcessors.
| |||||||||||
Set the ClassLoader to generate the proxy class in.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Return whether the Advisors returned by the subclass are pre-filtered to match the bean's target class already,
allowing the ClassFilter check to be skipped when building advisors chains for AOP invocations.
| |||||||||||
Determine the advisors for the given bean, including the specific interceptors as well as the common interceptor,
all adapted to the Advisor interface.
| |||||||||||
Create an AOP proxy for the given bean.
| |||||||||||
Subclasses may choose to implement this: for example, to change the interfaces exposed.
| |||||||||||
Return whether the given bean is to be proxied, what additional advices (e.g.
| |||||||||||
Return the owning BeanFactory.
| |||||||||||
Build a cache key for the given bean class and bean name.
| |||||||||||
Create a target source for bean instances.
| |||||||||||
This method is deprecated.
in favor of
isInfrastructureClass(beanClass) | |||||||||||
Return whether the given bean class represents an infrastructure class that should never be proxied.
| |||||||||||
Determine whether the given bean should be proxied with its target class rather than its interfaces.
| |||||||||||
Subclasses should override this method to return
true if the given bean should not be considered for
auto-proxying by this post-processor. | |||||||||||
Wrap the given bean if necessary, i.e.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.springframework.aop.framework.ProxyConfig
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
org.springframework.beans.factory.BeanClassLoaderAware
| |||||||||||
From interface
org.springframework.beans.factory.BeanFactoryAware
| |||||||||||
From interface
org.springframework.beans.factory.config.BeanPostProcessor
| |||||||||||
From interface
org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor
| |||||||||||
From interface
org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
| |||||||||||
From interface
org.springframework.core.Ordered
|
Convenience constant for subclasses: Return value for "do not proxy".
Convenience constant for subclasses: Return value for "proxy without additional interceptors, just the common ones".
Logger available to subclasses
BeansException |
---|
Create a proxy with the configured interceptors if the bean is identified as one to proxy by the subclass.
BeansException |
---|
BeansException |
---|
Specify the AdvisorAdapterRegistry to use. Default is the global AdvisorAdapterRegistry.
Set whether the common interceptors should be applied before bean-specific ones. Default is "true"; else, bean-specific interceptors will get applied first.
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.
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. |
---|
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.
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.
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.
order | ordering value |
---|
Set the ClassLoader to generate the proxy class in.
Default is the bean ClassLoader, i.e. the ClassLoader used by the containing BeanFactory for loading all bean classes. This can be overridden here for specific proxies.
Return whether the Advisors returned by the subclass are pre-filtered to match the bean's target class already, allowing the ClassFilter check to be skipped when building advisors chains for AOP invocations.
Default is false
. Subclasses may override this if they will always return pre-filtered Advisors.
Determine the advisors for the given bean, including the specific interceptors as well as the common interceptor, all adapted to the Advisor interface.
beanName | the name of the bean |
---|---|
specificInterceptors | the set of interceptors that is specific to this bean (may be empty, but not null) |
Create an AOP proxy for the given bean.
beanClass | the class of the bean |
---|---|
beanName | the name of the bean |
specificInterceptors | the set of interceptors that is specific to this bean (may be empty, but not null) |
targetSource | the TargetSource for the proxy, already pre-configured to access the bean |
Subclasses may choose to implement this: for example, to change the interfaces exposed.
The default implementation is empty.
proxyFactory | ProxyFactory that is already configured with TargetSource and interfaces and will be used to create the proxy immediably after this method returns |
---|
Return whether the given bean is to be proxied, what additional advices (e.g. AOP Alliance interceptors) and advisors to apply.
beanClass | the class of the bean to advise |
---|---|
beanName | the name of the bean |
customTargetSource | the TargetSource returned by the getCustomTargetSource(Class, String) method: may be ignored. Will be
null if no custom target source is in use. |
null
if no proxy at all, not even with the common
interceptors. See constants DO_NOT_PROXY and PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS.BeansException | in case of errors |
---|
Return the owning BeanFactory. May be null
, as this object doesn't need to belong to a bean factory.
Build a cache key for the given bean class and bean name.
beanClass | the bean class |
---|---|
beanName | the bean name |
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.
beanClass | the class of the bean to create a TargetSource for |
---|---|
beanName | the name of the bean |
This method is deprecated.
in favor of isInfrastructureClass(beanClass)
Return whether the given bean class and bean name represents an infrastructure class that should never be proxied.
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.
beanClass | the class of the bean |
---|
shouldSkip(Class, String)
Determine whether the given bean should be proxied with its target class rather than its interfaces. Checks the
"proxyTargetClass" setting
as well as the
AutoProxyUtils#PRESERVE_TARGET_CLASS_ATTRIBUTE "preserveTargetClass" attribute of the corresponding bean
definition.
beanClass | the class of the bean |
---|---|
beanName | the name of the bean |
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
.
beanClass | the class of the bean |
---|---|
beanName | the name of the bean |
Wrap the given bean if necessary, i.e. if it is eligible for being proxied.
bean | the raw bean instance |
---|---|
beanName | the name of the bean |
cacheKey | the cache key for metadata access |