类 ProxyFactoryBean

  • 所有已实现的接口:
    Serializable, Advised, TargetClassAware, Aware, BeanClassLoaderAware, BeanFactoryAware, FactoryBean<Object>

    public class ProxyFactoryBean
    extends ProxyCreatorSupport
    implements FactoryBean<Object>, BeanClassLoaderAware, BeanFactoryAware
    FactoryBean implementation that builds an AOP proxy based on beans in Spring 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 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 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.

    作者:
    Rod Johnson, Juergen Hoeller
    另请参阅:
    setInterceptorNames(java.lang.String...), setProxyInterfaces(java.lang.Class<?>[]), MethodInterceptor, Advisor, Advised, 序列化表格