org.springframework.beans.factory.FactoryBean implementation that builds an
AOP proxy based on beans in a Spring org.springframework.beans.factory.BeanFactory .
MethodInterceptors and
Advisors 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.; 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 — for example, "global*"
would match both "globalBean1" and "globalBean2"; whereas, "*" would match all
defined interceptors. The matching interceptors get applied according to their
returned order value, if they implement the org.
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 a 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, setProxyInterfaces, org.aopalliance.intercept.MethodInterceptor , org.springframework.aop.Advisor , Advised
| Modifier and Type | Class and Description |
|---|---|
| private static class | ProxyFactoryBean.
Used in the interceptor chain where we need to replace a bean with a prototype on creating a proxy. |
| Modifier and Type | Field and Description |
|---|---|
| private AdvisorAdapterRegistry | |
| private boolean | advisorChainInitialized
Whether the advisor chain has already been initialized. |
| private boolean | |
| private transient BeanFactory | |
| private transient boolean | |
| private boolean | |
| public static final String | GLOBAL_SUFFIX
This suffix in a value in an interceptor list indicates to expand globals. |
| private String[] | |
| protected final Log | |
| private transient ClassLoader | |
| private boolean | |
| private Object | singletonInstance
If this is a singleton, the cached singleton proxy instance. |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | addAdvisorOnChainCreation(Object
advice, advisor or target object next)Invoked when advice chain is created. |
| private void | addGlobalAdvisors(ListableBeanFactory beanFactory, String prefix)
Add all global interceptors and pointcuts. |
| protected void | adviceChanged()
Overrides org. Blow away and recache singleton on an advice change. |
| private void | checkInterceptorNames()
Check the interceptorNames list whether it contains a target name as final element. |
| private List | |
| private TargetSource | |
| public Object | Returns: a fresh AOP proxy reflecting the current state of this factoryImplements org. Return a proxy. |
| public Class | getObjectType()
Implements org. Return the type of the proxy. |
| protected Object | |
| private synchronized Object | Returns: the shared singleton proxyReturn the singleton instance of this class's proxy object, lazily creating it if it hasn't been created already. |
| private synchronized void | |
| private boolean | Returns: true if it's an Advisor or Advicebean name to check beanName)Look at bean factory metadata to work out whether this bean name, which concludes the interceptorNames list, is an Advisor or Advice, or may be a target. |
| public boolean | isSingleton()
Overrides default org. Is the object managed by this factory a singleton? |
| private Advisor | namedBeanToAdvisor(Object next)
Convert the following object sourced from calling getBean() on a name in the interceptorNames array to an Advisor or TargetSource. |
| private synchronized Object | Returns: a totally independent proxy, whose advice we may manipulate in isolationCreate a new prototype instance of this class's created proxy object, backed by an independent AdvisedSupport configuration. |
| private void | |
| public void | setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry)
Specify the AdvisorAdapterRegistry to use. |
| public void | setAutodetectInterfaces(boolean autodetectInterfaces)
Set whether to autodetect proxy interfaces if none specified. |
| public void | setBeanClassLoader(ClassLoader
the owning class loader classLoader)Implements org. Callback that supplies the bean |
| public void | setBeanFactory(BeanFactory
owning BeanFactory (never beanFactory)null).
The bean can immediately call methods on the factory.Implements org. Callback that supplies the owning factory to a bean instance. |
| public void | setFrozen(boolean frozen)
Overrides org. Set whether this config should be frozen. |
| public void | |
| public void | setProxyClassLoader(ClassLoader classLoader)
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. |
| public void | |
| public void | |
| public void |
| advisorAdapterRegistry | back to summary |
|---|---|
| private AdvisorAdapterRegistry advisorAdapterRegistry | |
| advisorChainInitialized | back to summary |
|---|---|
| private boolean advisorChainInitialized Whether the advisor chain has already been initialized. | |
| autodetectInterfaces | back to summary |
|---|---|
| private boolean autodetectInterfaces | |
| beanFactory | back to summary |
|---|---|
| private transient BeanFactory beanFactory
| |
| classLoaderConfigured | back to summary |
|---|---|
| private transient boolean classLoaderConfigured | |
| freezeProxy | back to summary |
|---|---|
| private boolean freezeProxy | |
| GLOBAL_SUFFIX | back to summary |
|---|---|
| public static final String GLOBAL_SUFFIX This suffix in a value in an interceptor list indicates to expand globals. | |
| interceptorNames | back to summary |
|---|---|
| private String[] interceptorNames
| |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| proxyClassLoader | back to summary |
|---|---|
| private transient ClassLoader proxyClassLoader
| |
| singleton | back to summary |
|---|---|
| private boolean singleton | |
| singletonInstance | back to summary |
|---|---|
| private Object singletonInstance If this is a singleton, the cached singleton proxy instance. | |
| targetName | back to summary |
|---|---|
| private String targetName
| |
| ProxyFactoryBean | back to summary |
|---|---|
| public ProxyFactoryBean() | |
| addAdvisorOnChainCreation | back to summary |
|---|---|
| private void addAdvisorOnChainCreation(Object next) Invoked when advice chain is created. Add the given advice, advisor or object to the interceptor list. Because of these three possibilities, we can't type the signature more strongly.
| |
| addGlobalAdvisors | back to summary |
|---|---|
| private void addGlobalAdvisors(ListableBeanFactory beanFactory, String prefix) Add all global interceptors and pointcuts. | |
| adviceChanged | back to summary |
|---|---|
| protected void adviceChanged() Overrides org. Blow away and recache singleton on an advice change.
| |
| checkInterceptorNames | back to summary |
|---|---|
| private void checkInterceptorNames() Check the interceptorNames list whether it contains a target name as final element. If found, remove the final name from the list and set it as targetName. | |
| freshAdvisorChain | back to summary |
|---|---|
| private List Return an independent advisor chain. We need to do this every time a new prototype instance is returned, to return distinct instances of prototype Advisors and Advices. | |
| freshTargetSource | back to summary |
|---|---|
| private TargetSource freshTargetSource() Return a TargetSource to use when creating a proxy. If the target was not specified at the end of the interceptorNames list, the TargetSource will be this class's TargetSource member. Otherwise, we get the target bean and wrap it in a TargetSource if necessary. | |
| getObject | back to summary |
|---|---|
| public Object getObject() throws BeansException Implements org. 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
| |
| getObjectType | back to summary |
|---|---|
| public Class Implements org. 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.
| |
| getProxy | back to summary |
|---|---|
| protected Object getProxy(AopProxy aopProxy) Return the proxy object to expose. The default implementation uses a
| |
| getSingletonInstance | back to summary |
|---|---|
| private synchronized Object getSingletonInstance() Return the singleton instance of this class's proxy object, lazily creating it if it hasn't been created already.
| |
| initializeAdvisorChain | back to summary |
|---|---|
| private synchronized void initializeAdvisorChain() throws AopConfigException, BeansException Create the advisor (interceptor) chain. Advisors that are sourced from a BeanFactory will be refreshed each time a new prototype instance is added. Interceptors added programmatically through the factory API are unaffected by such changes. | |
| isNamedBeanAnAdvisorOrAdvice | back to summary |
|---|---|
| private boolean isNamedBeanAnAdvisorOrAdvice(String beanName) Look at bean factory metadata to work out whether this bean name, which concludes the interceptorNames list, is an Advisor or Advice, or may be a target.
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| namedBeanToAdvisor | back to summary |
|---|---|
| private Advisor namedBeanToAdvisor(Object next) Convert the following object sourced from calling getBean() on a name in the interceptorNames array to an Advisor or TargetSource. | |
| newPrototypeInstance | back to summary |
|---|---|
| private synchronized Object newPrototypeInstance() Create a new prototype instance of this class's created proxy object, backed by an independent AdvisedSupport configuration.
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException Hides org. | |
| setAdvisorAdapterRegistry | back to summary |
|---|---|
| public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) Specify the AdvisorAdapterRegistry to use. Default is the global AdvisorAdapterRegistry. | |
| setAutodetectInterfaces | back to summary |
|---|---|
| public void setAutodetectInterfaces(boolean autodetectInterfaces) 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.
| |
| setBeanClassLoader | back to summary |
|---|---|
| public void setBeanClassLoader(ClassLoader classLoader) Implements org. Doc from org. Callback that supplies the bean Invoked after the population of normal bean properties but
before an initialization callback such as
| |
| setBeanFactory | back to summary |
|---|---|
| public void setBeanFactory(BeanFactory beanFactory) Implements org. Doc from org. Callback that supplies the owning factory to a bean instance. Invoked after the population of normal bean properties
but before an initialization callback such as
| |
| setFrozen | back to summary |
|---|---|
| public void setFrozen(boolean frozen) Overrides org. Doc from org. Set whether this config should be frozen. 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.
| |
| setInterceptorNames | back to summary |
|---|---|
| public void setInterceptorNames(String... interceptorNames) 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 | |
| setProxyClassLoader | back to summary |
|---|---|
| public void setProxyClassLoader(ClassLoader classLoader) 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. | |
| setProxyInterfaces | back to summary |
|---|---|
| public void setProxyInterfaces(Class<?>[] proxyInterfaces) throws ClassNotFoundException 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". | |
| setSingleton | back to summary |
|---|---|
| public void setSingleton(boolean singleton) 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. | |
| setTargetName | back to summary |
|---|---|
| public void setTargetName(String targetName) 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. | |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Advice | getAdvice()
Implements org. Return the advice part of this aspect. |
| public String | |
| public String |
| beanName | back to summary |
|---|---|
| private final String beanName | |
| message | back to summary |
|---|---|
| private final String message | |
| PrototypePlaceholderAdvisor | back to summary |
|---|---|
| public PrototypePlaceholderAdvisor(String beanName) | |
| getAdvice | back to summary |
|---|---|
| public Advice getAdvice() Implements org. Doc from org. Return the advice part of this aspect. An advice may be an interceptor, a before advice, a throws advice, etc. | |
| getBeanName | back to summary |
|---|---|
| public String getBeanName() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |