文章目录
ExposeInvocationInterceptor
从英文名字,顾名思义,暴露调用器的拦截器。
其就是起了暴露一个调用器作用的拦截器。
- 1、那么其暴露了什么调用器?
- 2、是如何暴露的,通过什么方法实现?
- 3、暴露给谁?
- 4、在什么时候起到拦截作用?
下面带着以上问题,通过示例代码来分析spring Aop源码
示例代码
源码分析
extendAdvisors
在初始化完Bean,调用AbstractAutoProcxyCreator的后置处理方法postProcessAfterInitialization的时候,对adivisors进行了扩展,添加了ExposeInvocationInterceptor拦截器
makeAdvisorChainAspectJCapableIfNecessary
实际添加了ExposeInvocationInterceptor拦截器的地方
作者英文注释:
/**
* Add special advisors if necessary to work with a proxy chain that contains AspectJ advisors.
* This will expose the current Spring AOP invocation (necessary for some AspectJ pointcut matching)
* and make available the current AspectJ JoinPoint. The call will have no effect if there are no
* AspectJ advisors in the advisor chain.
* @param advisors Advisors available
* @return {@code true} if any special {@link Advisor Advisors} were added, otherwise {@code false}.
*/
添加扩展拦截器的调用链
方法栈图示
完整方法栈
makeAdvisorChainAspectJCapableIfNecessary:44, AspectJProxyUtils (org.springframework.aop.aspectj)
extendAdvisors:97, AspectJAwareAdvisorAutoProxyCreator