public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (bean instanceof AopInfrastructureBean) {
      // Ignore AOP infrastructure such as scoped proxies.
      return bean;
    }

    Class<?> targetClass = AopUtils.getTargetClass(bean);
    if (targetClass == null) {
      // Can't do much here.
      return bean;
    }

    if (AopUtils.canApply(this.asyncAnnotationAdvisor, targetClass)) {
      if (bean instanceof Advised) {
        ((Advised) bean).addAdvisor(this.asyncAnnotationAdvisor);
        return bean;
      } else {
        ProxyFactory proxyFactory = new ProxyFactory(bean);
        // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig.
        proxyFactory.copyFrom(this);
        proxyFactory.addAdvisor(this.asyncAnnotationAdvisor);
        return proxyFactory.getProxy(this.beanClassLoader);
      }
    } else {
      // No async proxy needed.
      return bean;
    }
  }
 private Object applyAdvice(Object bean, PointcutAdvisor advisor, ClassLoader beanClassLoader) {
   Class<?> targetClass = AopUtils.getTargetClass(bean);
   if (AopUtils.canApply(advisor.getPointcut(), targetClass)) {
     if (bean instanceof Advised) {
       ((Advised) bean).addAdvisor(advisor);
       return bean;
     } else {
       ProxyFactory proxyFactory = new ProxyFactory(bean);
       proxyFactory.addAdvisor(advisor);
       /**
        * N.B. it's not a good idea to use proxyFactory.setProxyTargetClass(true) here because it
        * forces all the integration components to be cglib proxyable (i.e. have a default
        * constructor etc.), which they are not in general (usually for good reason).
        */
       return proxyFactory.getProxy(beanClassLoader);
     }
   }
   return bean;
 }