Spring---AOP


/**
     *  【Spring-AOP实现】
     *      org.springframework.aop.framework.AopProxy
     *          Delegate interface for a configured AOP proxy, allowing for the creation of actual proxy objects.
     *          Out-of-the-box implementations are available for JDK dynamic proxies and for CGLIB proxies, as applied by DefaultAopProxyFactory.
     *
     *          public interface AopProxy {
     *              Object getProxy();
     *              Object getProxy(@Nullable ClassLoader classLoader);
     *          }
     *
     *
     *          org.springframework.aop.framework.JdkDynamicAopProxy
     *              JDK-based AopProxy implementation for the Spring AOP framework, based on JDK java.lang.reflect.Proxy dynamic proxies. 基于JDK动态代理实现;
     *              Objects of this type should be obtained through proxy factories, configured by an  AdvisedSupport class. 该类型的代理对象 应该由工厂提供,工厂由AdvisedSupport提供支持;
     *
     *              final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializable {
     *
     *                  private final AdvisedSupport advised;
     *
     *                  public Object getProxy() {
     *                      return getProxy(ClassUtils.getDefaultClassLoader());
     *                  }
     *                  public Object getProxy(@Nullable ClassLoader classLoader) {
     *                      ...
     *                      return Proxy.newProxyInstance(classLoader, proxiedInterfaces, this);
     *                  }
     *
     *                  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {}
     *              }
     *
     *
     *          org.springframework.aop.framework.CglibAopProxy
     *              CGLIB-based AopProxy implementation for the Spring AOP framework. 基于CGLB的AOP代理实现;
     *              Objects of this type should be obtained through proxy factories, configured by an AdvisedSupport object. 该类型的代理对象 应该由工厂提供,工厂由AdvisedSupport提供支持;
     *              DefaultAopProxyFactory will automatically create CGLIB-based proxies if necessary, for example in case of proxying a target class. 如果需要创建代理对象,DefaultAopProxyFactory将会创建CGLB代理对象;
     *
     *              class CglibAopProxy implements AopProxy, Serializable {
     *
     *                  protected final AdvisedSupport advised;
     *
     *                  public Object getProxy() {
     *                      return getProxy(null);
     *                  }
     *                  public Object getProxy(@Nullable ClassLoader classLoader) {
     *
     *                  }
     *
     *                  private static class DynamicAdvisedInterceptor implements MethodInterceptor, Serializable {
     *                      public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {}
     *                  }
     *                  ...
     *              }
     *
     *
     *
     *      org.springframework.aop.framework.AopProxyFactory
     *          Interface to be implemented by factories that are able to create AOP proxies based on {@link AdvisedSupport} configuration objects. 被代理工厂类实现 能够 基于AdvisedSupport  创建AOP代理类;
     *
     *          public interface AopProxyFactory {
     *              AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException;
     *          }
     *
     *      org.springframework.aop.framework.DefaultAopProxyFactory
     *          Default {@link AopProxyFactory} implementation, creating either a CGLIB proxy or a JDK dynamic proxy. 默认的AopProxyFactory实现;
     *
     *          public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
     *              public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
     *                  if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {
     *                      Class<?> targetClass = config.getTargetClass();
     *                      if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) {
     * 				            return new JdkDynamicAopProxy(config);
     *                      }
     * 			            return new ObjenesisCglibAopProxy(config);
     *                  }
     *                  else{
     *                      return new JdkDynamicAopProxy(config);
     *                  }
     *              }
     *          }
     *
     *      org.springframework.aop.framework.ProxyCreatorSupport
     *          Base class for proxy factories. 代理工厂的基类;
     *          Provides convenient access to a configurable AopProxyFactory. 提供便捷的方式访问AopProxyFactory;
     *
     *          public class ProxyCreatorSupport extends AdvisedSupport {
     *
     *              private AopProxyFactory aopProxyFactory;
     *
     *              public AopProxyFactory getAopProxyFactory() {
     * 		            return this.aopProxyFactory;
     *              }
     *
     *              protected final synchronized AopProxy createAopProxy() {
     *                  ...
     *                  return getAopProxyFactory().createAopProxy(this);
     *              }
     *          }
     *
     *      org.springframework.aop.framework.ProxyFactory
     *          public class ProxyFactory extends ProxyCreatorSupport {
     *
     *              public Object getProxy(@Nullable ClassLoader classLoader) {
     * 		            return createAopProxy().getProxy(classLoader);                ---createAopProxy() :使用DefaultAopProxyFactory创建对应的AopProxy;
     * 		                                                                                                   ProxyFactory.getProxy
     * 		                                                                                                -> ProxyCreatorSupport.createAopProxy
     * 		                                                                                                -> ProxyCreatorSupport.getAopProxyFactory
     * 		                                                                                                -> AopProxyFactory.createAopProxy
     * 		                                                                                                -> DefaultAopProxyFactory.createAopProxy
     * 		                                                                          ---getProxy(classLoader) : 不同的AopProxy创建不同的AOP代理对象;
     *
     *              }
     *          }
     *
     *
     *      实现思路:BeanPostProcessor#postProcessAfterInitialization
     *
     *      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#initializeBean
     *
     *      ->
     *
     *      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsAfterInitialization
     *
     *      ->
     *
     *      不同的BeanPostProcessor有不同的实现
     *          eg:
     *              BeanPostProcessor : org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
     *                  @Aspect
     *                      org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#postProcessAfterInitialization{
     *
     *                          ...
     *                          return wrapIfNecessary(bean, beanName, cacheKey);
     *                          ...
     *
     *                      }
     *
     *                      protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
     *                          ...
     *                          if (specificInterceptors != DO_NOT_PROXY) {
     *                              ...
     *                              Object proxy = createProxy(bean.getClass(), beanName, specificInterceptors, new SingletonTargetSource(bean));
     * 				                ...
     *                          }
     *                          ...
     *                      }
     *
     *                      protected Object createProxy(Class<?> beanClass, @Nullable String beanName, @Nullable Object[] specificInterceptors, TargetSource targetSource) {
     *                          ...
     *                          ProxyFactory proxyFactory = new ProxyFactory();
     *                          ...
     *                          proxyFactory.addAdvisors(advisors);
     *                          ...
     *                          return proxyFactory.getProxy(getProxyClassLoader());
     *                      }
     *
     *                  事务
     *                      org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#postProcessAfterInitialization
     *
     *
     *              BeanPostProcessor : org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor
     *                  @Async
     *                      org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor#postProcessAfterInitialization{
     *                          ...
     *                          if (isEligible(bean, beanName)) {
     *                              ProxyFactory proxyFactory = prepareProxyFactory(bean, beanName);
     *                              ...
     *                              proxyFactory.addAdvisor(this.advisor);
     *                              ...
     *                              return proxyFactory.getProxy(getProxyClassLoader());
     *                          }
     *                      }
     *
     *
     */