ProxyFactoryBean

Spring provides a classic way of creating proxies of objects manually using ProxyFactoryBean, which will create an AOP proxy wrapping the target object. ProxyFactoryBean provides a way to set advice and advisors that are eventually merged into an AOP proxy. The key properties inherited from the org.springframework.aop.framework.ProxyConfig superclass for all AOP proxy factories in Spring are as follows:

  • proxyTargetClass: If it's true, then the proxy is created using CGLIB only. If it's not set, the proxy will be created using the JDK proxy if the target class implements the interface; otherwise, the proxy will be created using CGLIB.
  • optimizeFor the CGLIB proxy, this instructs the proxy to apply some aggressive optimizations. Currently, it is not supported by the JDK proxy. This needs to be used wisely.
  • frozen: If a proxy is set as frozen, then changes to the configuration are not allowed. This is useful when we don't want callers to modify the proxy after the proxy has been created. This is used for optimization. The default value of this property is false.
  • exposeProxy: Setting this property to true determines whether the current proxy should be exposed to ThreadLocal or not. If it's exposed to ThreadLocal, then the target can use the AopContext.currentProxy() method for self-invocation of the method.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset