开局一张图,我们先上张图


类的说明和继承关系
/**
* Base class for {@link BeanPostProcessor} implementations that apply a
* Spring AOP {@link Advisor} to specific beans.
*
* @author Juergen Hoeller
* @since 3.2
*/
@SuppressWarnings("serial")
public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSupport implements BeanPostProcessor 具体来看怎么处理的bean 主要两个方法
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean;
} @Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof AopInfrastructureBean || this.advisor == null) {
// Ignore AOP infrastructure such as scoped proxies.
return bean;
} if (bean instanceof Advised) {
Advised advised = (Advised) bean;
if (!advised.isFrozen() && isEligible(AopUtils.getTargetClass(bean))) {
// Add our local Advisor to the existing proxy's Advisor chain...
if (this.beforeExistingAdvisors) {
advised.addAdvisor(0, this.advisor);
}
else {
advised.addAdvisor(this.advisor);
}
return bean;
}
} if (isEligible(bean, beanName)) {
ProxyFactory proxyFactory = prepareProxyFactory(bean, beanName);
if (!proxyFactory.isProxyTargetClass()) {
evaluateProxyInterfaces(bean.getClass(), proxyFactory);
}
proxyFactory.addAdvisor(this.advisor);
customizeProxyFactory(proxyFactory);
return proxyFactory.getProxy(getProxyClassLoader());
} // No async proxy needed.
return bean;
} 这段代码 主要逻辑 advised.addAdvisor(this.advisor);//添加上需要的advisor
         
再看个实现

*
* <p>Note: The underlying async advisor applies before existing advisors by default,
* in order to switch to async execution as early as possible in the invocation chain.
*
* @author Mark Fisher
* @author Juergen Hoeller
* @author Stephane Nicoll
* @since 3.0
* @see Async
* @see AsyncAnnotationAdvisor
* @see #setBeforeExistingAdvisors
* @see ScheduledAnnotationBeanPostProcessor
*/
@SuppressWarnings("serial")
public class AsyncAnnotationBeanPostProcessor extends AbstractBeanFactoryAwareAdvisingPostProcessor {

   /**
* The default name of the {@link TaskExecutor} bean to pick up: "taskExecutor".
* <p>Note that the initial lookup happens by type; this is just the fallback
* in case of multiple executor beans found in the context.
* @since 4.2
* @see AnnotationAsyncExecutionInterceptor#DEFAULT_TASK_EXECUTOR_BEAN_NAME
*/
public static final String DEFAULT_TASK_EXECUTOR_BEAN_NAME =
AnnotationAsyncExecutionInterceptor.DEFAULT_TASK_EXECUTOR_BEAN_NAME; protected final Log logger = LogFactory.getLog(getClass()); @Nullable
private Class<? extends Annotation> asyncAnnotationType; @Nullable
private Executor executor; @Nullable
private AsyncUncaughtExceptionHandler exceptionHandler; public AsyncAnnotationBeanPostProcessor() {
setBeforeExistingAdvisors(true);
} /**
* Set the 'async' annotation type to be detected at either class or method
* level. By default, both the {@link Async} annotation and the EJB 3.1
* {@code javax.ejb.Asynchronous} annotation will be detected.
* <p>This setter property exists so that developers can provide their own
* (non-Spring-specific) annotation type to indicate that a method (or all
* methods of a given class) should be invoked asynchronously.
* @param asyncAnnotationType the desired annotation type
*/
public void setAsyncAnnotationType(Class<? extends Annotation> asyncAnnotationType) {
Assert.notNull(asyncAnnotationType, "'asyncAnnotationType' must not be null");
this.asyncAnnotationType = asyncAnnotationType;
} /**
* Set the {@link Executor} to use when invoking methods asynchronously.
* <p>If not specified, default executor resolution will apply: searching for a
* unique {@link TaskExecutor} bean in the context, or for an {@link Executor}
* bean named "taskExecutor" otherwise. If neither of the two is resolvable,
* a local default executor will be created within the interceptor.
* @see AsyncAnnotationAdvisor#AsyncAnnotationAdvisor(Executor, AsyncUncaughtExceptionHandler)
* @see AnnotationAsyncExecutionInterceptor#getDefaultExecutor(BeanFactory)
* @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME
*/
public void setExecutor(Executor executor) {
this.executor = executor;
} /**
* Set the {@link AsyncUncaughtExceptionHandler} to use to handle uncaught
* exceptions thrown by asynchronous method executions.
* @since 4.1
*/
public void setExceptionHandler(AsyncUncaughtExceptionHandler exceptionHandler) {
this.exceptionHandler = exceptionHandler;
} @Override
public void setBeanFactory(BeanFactory beanFactory) {
super.setBeanFactory(beanFactory); AsyncAnnotationAdvisor advisor = new AsyncAnnotationAdvisor(this.executor, this.exceptionHandler);
if (this.asyncAnnotationType != null) {
advisor.setAsyncAnnotationType(this.asyncAnnotationType);
}
advisor.setBeanFactory(beanFactory);
this.advisor = advisor;
} }
其中AbstractBeanFactoryAwareAdvisingPostProcessor继承了AbstractAdvisingBeanPostProcessor 类,所以AsyncAnnotationBeanPostProcessor也是AbstractAdvisingBeanPostProcessor的一个子类。它并没有重写 postProcessAfterInitialization 方法,所以方法和原类的实现一样。
												

最新文章

  1. react-router 组件式配置与对象式配置小区别
  2. linux 给文件夹权限
  3. 极值问题(acms)
  4. iOS ZBarSDK的基本使用:扫描
  5. 【Linux/Ubuntu学习6】unbuntu 下载android源码
  6. codevs 1066 引水入城
  7. 高效算法——B 抄书 copying books,uva714
  8. @Valid springMVC bean校验不起作用及如何统一处理校验
  9. asp.net mvc使用validate.js验证 若name属性包含特殊字符则加上双引号即可
  10. UVa 336 - A Node Too Far
  11. 《Machine Learning》系列学习笔记之第四周
  12. IIC模块TestBench的书写方法
  13. Mysql事务与锁详解
  14. 安卓开发学习笔记(五):史上最简单且华丽地实现Android Stutio当中Webview控件https/http协议的方法
  15. Codeforces 994F Compute Power 二分+DP
  16. 47.HTML---frame,iframe,frameset之间的关系与区别
  17. Python_summary
  18. 使用maven profile实现多环境配置相关打包
  19. Hibernate学习笔记2.1(Hibernate基础配置)
  20. 哈佛大学 Machine Learning

热门文章

  1. 手机端sticker布局,底部按钮在屏幕底部
  2. manjaro安装anaconda出错
  3. bat 处理adb脚本
  4. leetcode NO.171 Excel表列序号 (python实现)
  5. OAuth 开放授权
  6. c语言有用函数收集
  7. 【BZOJ1717】[Usaco2006 Dec]Milk Patterns 产奶的模式 (二分+SA)
  8. POJ2723 Get Luffy Out 【2-sat】
  9. [LVS] 用keepalived实现LVS NAT模式高可用性
  10. 【11】vue router 之导航钩子