|
||||||||||
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.AdvisedSupport org.springframework.aop.framework.ProxyFactoryBean
public class ProxyFactoryBean
FactoryBean implementation for use to source AOP proxies from a Spring BeanFactory.
Interceptors and Advisors are identified by a list of bean names in the current bean factory. These beans should be of type Interceptor or Advisor. The last entry in the list can be the name of any bean in the factory. If it's neither an Interceptor nor an Advisor, a new SingletonTargetSource is added to wrap it. If it;s a TargetSource, it is used as this proxy factory's TargetSource. It's normally preferred to use the "targetSource" property to set the TargetSource. It is not possible to use both the targetSource property and an interceptor name: this is treated as a configuration error.
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 Ordered interface. An interceptor name list may not conclude with a global "xxx*" pattern, as global interceptors cannot invoke targets.
Creates a J2SE proxy when proxy interfaces are given, 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.
setInterceptorNames(java.lang.String[])
,
setProxyInterfaces(java.lang.String[])
,
MethodInterceptor
,
Advised
,
SingletonTargetSource
,
Serialized FormField Summary | |
---|---|
static String |
GLOBAL_SUFFIX
This suffix in a value in an interceptor list indicates to expand globals. |
Fields inherited from class org.springframework.aop.framework.AdvisedSupport |
---|
advisorChainFactory, EMPTY_TARGET_SOURCE, targetSource |
Fields inherited from class org.springframework.aop.framework.ProxyConfig |
---|
exposeProxy, logger |
Constructor Summary | |
---|---|
ProxyFactoryBean()
|
Method Summary | |
---|---|
void |
activated(AdvisedSupport advisedSupport)
Invoked when first proxy is created. |
void |
adviceChanged(AdvisedSupport advisedSupport)
Blow away and recache singleton on an advice change. |
Object |
getObject()
Return a proxy. |
Class |
getObjectType()
Return the type of the proxy. |
protected Object |
getProxy(AopProxy aopProxy)
Return the proxy object to expose. |
boolean |
isSingleton()
Is the bean managed by this factory a singleton or a prototype? |
void |
setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry)
Specify the AdvisorAdapterRegistry to use. |
void |
setAutodetectInterfaces(boolean autodetectInterfaces)
Set whether to autodetect proxy interfaces if none specified. |
void |
setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance. |
void |
setFrozen(boolean frozen)
Set whether this config should be frozen. |
void |
setInterceptorNames(String[] interceptorNames)
Set the list of Advice/Advisor bean names. |
void |
setProxyInterfaces(String[] interfaceNames)
Set the names of the interfaces we're proxying. |
void |
setSingleton(boolean singleton)
Set the value of the singleton property. |
void |
setTargetName(String targetName)
Set the name of the target bean. |
Methods inherited from class org.springframework.aop.framework.AdvisedSupport |
---|
addAdvice, addAdvice, addAdvisor, addAdvisor, addAdvisor, addInterface, addListener, adviceIncluded, copyConfigurationFrom, copyConfigurationFrom, countAdvicesOfType, createAopProxy, getAdvisorChainFactory, getAdvisors, getProxiedInterfaces, getTargetSource, indexOf, indexOf, isActive, isInterfaceProxied, readResolve, removeAdvice, removeAdvisor, removeAdvisor, removeInterface, removeListener, replaceAdvisor, setAdvisorChainFactory, setInterfaces, setTarget, setTargetSource, toProxyConfigString, toString, writeReplace |
Methods inherited from class org.springframework.aop.framework.ProxyConfig |
---|
copyFrom, getAopProxyFactory, isExposeProxy, isFrozen, isOpaque, isOptimize, isProxyTargetClass, setAopProxyFactory, setExposeProxy, setOpaque, setOptimize, setProxyTargetClass |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.springframework.aop.framework.Advised |
---|
isExposeProxy, isFrozen, isProxyTargetClass, setExposeProxy |
Field Detail |
---|
public static final String GLOBAL_SUFFIX
Constructor Detail |
---|
public ProxyFactoryBean()
Method Detail |
---|
public void setProxyInterfaces(String[] interfaceNames) throws ClassNotFoundException
Alternatively, use the "interfaces" property of type Class array (the bean factory will automatically convert from String to Class there).
ClassNotFoundException
AdvisedSupport.setInterfaces(java.lang.Class[])
public void setInterceptorNames(String[] interceptorNames)
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.
MethodInterceptor
,
Advisor
,
Advice
,
SingletonTargetSource
public void setTargetName(String targetName)
You can also specify a target object or a TargetSource object directly, via the "target"/"targetSource" property, respectively.
setInterceptorNames(String[])
,
AdvisedSupport.setTarget(Object)
,
AdvisedSupport.setTargetSource(org.springframework.aop.TargetSource)
public void setAutodetectInterfaces(boolean autodetectInterfaces)
Default is "false": If no proxy interfaces specified, a CGLIB proxy for the full target class will be created. Specify "true" to autodetect all interfaces implemented by the target class in this case.
public void setSingleton(boolean singleton)
public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry)
GlobalAdvisorAdapterRegistry
public void setFrozen(boolean frozen)
ProxyConfig
When a config is frozen, no advice changes can be made. This is useful for optimization, and useful when we don't want callers to be able to manipulate configuration after casting to Advised.
setFrozen
in class ProxyConfig
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
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.
BeansException
- in case of initialization errorsBeanInitializationException
public Object getObject() throws BeansException
getObject()
for a proxy.
getObject
in interface FactoryBean
BeansException
FactoryBeanNotInitializedException
public Class getObjectType()
getObjectType
in interface FactoryBean
null
if not known at the time of the callTargetSource.getTargetClass()
public boolean isSingleton()
FactoryBean
getObject()
always return the same object
(a reference that can be cached)?
NOTE: If a FactoryBean indicates to hold a singleton object,
the object returned from getObject()
might get cached
by the owning BeanFactory. Hence, do not return true
unless the FactoryBean always exposes the same reference.
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
isSingleton
in interface FactoryBean
FactoryBean.getObject()
protected Object getProxy(AopProxy aopProxy)
Default implementation uses a plain getProxy()
call.
Can be overridden to specify a custom class loader.
aopProxy
- the prepared AopProxy instance to get the proxy from
AopProxy.getProxy()
,
AopProxy.getProxy(ClassLoader)
public void activated(AdvisedSupport advisedSupport)
AdvisedSupportListener
activated
in interface AdvisedSupportListener
advisedSupport
- the AdvisedSupport objectAdvisedSupportListener.activated(org.springframework.aop.framework.AdvisedSupport)
public void adviceChanged(AdvisedSupport advisedSupport)
adviceChanged
in interface AdvisedSupportListener
advisedSupport
- the AdvisedSupport objectAdvisedSupportListener.adviceChanged(org.springframework.aop.framework.AdvisedSupport)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |