Class AopProxyBeanPostProcessor

java.lang.Object
com.ultikits.ultitools.aop.AopProxyBeanPostProcessor
All Implemented Interfaces:
BeanPostProcessor

public class AopProxyBeanPostProcessor extends Object implements BeanPostProcessor
BeanPostProcessor that creates AOP proxies for beans that need interception.

This processor checks each bean during initialization and creates a CGLIB proxy if any registered AopAdvisor matches the bean's methods.

Usage example:


 AopProxyBeanPostProcessor aopProcessor = new AopProxyBeanPostProcessor();
 aopProcessor.addAdvisor(AopAdvisor.forAnnotation(Transactional.class, txInterceptor, 100));
 container.addBeanPostProcessor(aopProcessor);
 
Since:
6.2.0
Author:
wisdomme
  • Field Details

  • Constructor Details

    • AopProxyBeanPostProcessor

      public AopProxyBeanPostProcessor()
  • Method Details

    • addAdvisor

      public void addAdvisor(AopAdvisor advisor)
      Adds an advisor to be applied during proxy creation.
      Parameters:
      advisor - the advisor to add
    • removeAdvisor

      public boolean removeAdvisor(AopAdvisor advisor)
      Removes an advisor.
      Parameters:
      advisor - the advisor to remove
      Returns:
      true if the advisor was removed
    • getAdvisors

      public List<AopAdvisor> getAdvisors()
      Gets all registered advisors.
      Returns:
      an unmodifiable list of advisors
    • postProcessAfterInitialization

      public Object postProcessAfterInitialization(Object bean, String beanName)
      Description copied from interface: BeanPostProcessor
      Apply this BeanPostProcessor to the given new bean instance after any bean initialization callbacks.
      在任何Bean初始化回调之后,将此BeanPostProcessor应用于给定的新Bean实例。
      Specified by:
      postProcessAfterInitialization in interface BeanPostProcessor
      Parameters:
      bean - the new bean instance
      新的Bean实例
      beanName - the name of the bean
      Bean的名称
      Returns:
      the bean instance to use
      要使用的Bean实例
    • getApplicableInterceptors

      private List<MethodInterceptor> getApplicableInterceptors(Class<?> targetClass)
      Gets all interceptors that apply to the given class.
    • requiresProxy

      private boolean requiresProxy(Class<?> targetClass)
      Checks if the given class requires a proxy based on any advisor.