open class ProxyFactoryBean : ProxyCreatorSupport, FactoryBean<Any>, BeanClassLoaderAware, BeanFactoryAware
org.springframework.beans.factory.FactoryBean implementation that builds an AOP proxy based on beans in Spring org.springframework.beans.factory.BeanFactory.
org.aopalliance.intercept.MethodInterceptor and org.springframework.aop.Advisor are identified by a list of bean names in the current bean factory, specified through the "interceptorNames" property. The last entry in the list can be the name of a target bean or a org.springframework.aop.TargetSource; however, it is normally preferable to use the "targetName"/"target"/"targetSource" properties instead.
Global interceptors and advisors can be added at the factory level. The specified ones are expanded in an interceptor list where an "xxx*" entry is included in the list, matching the given prefix with the bean names (e.g. "global*" would match both "globalBean1" and "globalBean2", "*" all defined interceptors). The matching interceptors get applied according to their returned order value, if they implement the org.springframework.core.Ordered interface.
Creates a JDK proxy when proxy interfaces are given, and a CGLIB proxy for the actual target class if not. Note that the latter will only work if the target class does not have final methods, as a dynamic subclass will be created at runtime.
It's possible to cast a proxy obtained from this factory to Advised, or to obtain the ProxyFactoryBean reference and programmatically manipulate it. This won't work for existing prototype references, which are independent. However, it will work for prototypes subsequently obtained from the factory. Changes to interception will work immediately on singletons (including existing references). However, to change interfaces or target it's necessary to obtain a new instance from the factory. This means that singleton instances obtained from the factory do not have the same object identity. However, they do have the same interceptors and target, and changing any reference will change all objects.
Author
Rod Johnson
Author
Juergen Hoeller
See Also
#setInterceptorNames#setProxyInterfacesorg.aopalliance.intercept.MethodInterceptororg.springframework.aop.AdvisorAdvised
ProxyFactoryBean()
org.springframework.beans.factory.FactoryBean implementation that builds an AOP proxy based on beans in Spring org.springframework.beans.factory.BeanFactory. org.aopalliance.intercept.MethodInterceptor and org.springframework.aop.Advisor are identified by a list of bean names in the current bean factory, specified through the "interceptorNames" property. The last entry in the list can be the name of a target bean or a org.springframework.aop.TargetSource; however, it is normally preferable to use the "targetName"/"target"/"targetSource" properties instead. Global interceptors and advisors can be added at the factory level. The specified ones are expanded in an interceptor list where an "xxx*" entry is included in the list, matching the given prefix with the bean names (e.g. "global*" would match both "globalBean1" and "globalBean2", "*" all defined interceptors). The matching interceptors get applied according to their returned order value, if they implement the org.springframework.core.Ordered interface. Creates a JDK proxy when proxy interfaces are given, and a CGLIB proxy for the actual target class if not. Note that the latter will only work if the target class does not have final methods, as a dynamic subclass will be created at runtime. It's possible to cast a proxy obtained from this factory to Advised, or to obtain the ProxyFactoryBean reference and programmatically manipulate it. This won't work for existing prototype references, which are independent. However, it will work for prototypes subsequently obtained from the factory. Changes to interception will work immediately on singletons (including existing references). However, to change interfaces or target it's necessary to obtain a new instance from the factory. This means that singleton instances obtained from the factory do not have the same object identity. However, they do have the same interceptors and target, and changing any reference will change all objects. |
static val GLOBAL_SUFFIX: String
This suffix in a value in an interceptor list indicates to expand globals. |
open fun getObject(): Any
Return a proxy. Invoked when clients obtain beans from this factory bean. Create an instance of the AOP proxy to be returned by this factory. The instance will be cached for a singleton, and create on each call to |
|
open fun getObjectType(): Class<*>
Return the type of the proxy. Will check the singleton instance if already created, else fall back to the proxy interface (in case of just a single one), the target bean type, or the TargetSource's target class. |
|
open fun isSingleton(): Boolean |
|
open fun setAdvisorAdapterRegistry(advisorAdapterRegistry: AdvisorAdapterRegistry): Unit
Specify the AdvisorAdapterRegistry to use. Default is the global AdvisorAdapterRegistry. |
|
open fun setAutodetectInterfaces(autodetectInterfaces: Boolean): Unit
Set whether to autodetect proxy interfaces if none specified. Default is "true". Turn this flag off to create a CGLIB proxy for the full target class if no interfaces specified. |
|
open fun setBeanClassLoader(classLoader: ClassLoader): Unit |
|
open fun setBeanFactory(beanFactory: BeanFactory): Unit |
|
open fun setFrozen(frozen: Boolean): Unit |
|
open fun setInterceptorNames(vararg interceptorNames: String): Unit
Set the list of Advice/Advisor bean names. This must always be set to use this factory bean in a bean factory. The referenced beans should be of type Interceptor, Advisor or Advice The last entry in the list can be the name of any bean in the factory. If it's neither an Advice nor an Advisor, a new SingletonTargetSource is added to wrap it. Such a target bean cannot be used if the "target" or "targetSource" or "targetName" property is set, in which case the "interceptorNames" array must contain only Advice/Advisor bean names. NOTE: Specifying a target bean as final name in the "interceptorNames" list is deprecated and will be removed in a future Spring version. Use the |
|
open fun setProxyClassLoader(classLoader: ClassLoader): Unit
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. |
|
open fun setProxyInterfaces(proxyInterfaces: Array<Class<*>>): Unit
Set the names of the interfaces we're proxying. If no interface is given, a CGLIB for the actual class will be created. This is essentially equivalent to the "setInterfaces" method, but mirrors TransactionProxyFactoryBean's "setProxyInterfaces". |
|
open fun setSingleton(singleton: Boolean): Unit
Set the value of the singleton property. Governs whether this factory should always return the same proxy instance (which implies the same target) or whether it should return a new prototype instance, which implies that the target and interceptors may be new instances also, if they are obtained from prototype bean definitions. This allows for fine control of independence/uniqueness in the object graph. |
|
open fun setTargetName(targetName: String): Unit
Set the name of the target bean. This is an alternative to specifying the target name at the end of the "interceptorNames" array. You can also specify a target object or a TargetSource object directly, via the "target"/"targetSource" property, respectively. |