Spring AOP 源码探索 之 链式调用中的 ExposeInvocationInterceptor拦截器作用

本文深入探讨了Spring AOP中的ExposeInvocationInterceptor拦截器,解释了它如何暴露MethodInvocation,何时以及为何需要。文章通过示例代码、源码分析以及调用链流程揭示了其在链式调用中的关键作用,特别是在与AspectJ集成时提供当前调用信息的重要性。
摘要由CSDN通过智能技术生成

ExposeInvocationInterceptor

从英文名字,顾名思义,暴露调用器的拦截器。
其就是起了暴露一个调用器作用的拦截器。

  • 1、那么其暴露了什么调用器?
  • 2、是如何暴露的,通过什么方法实现?
  • 3、暴露给谁?
  • 4、在什么时候起到拦截作用?

下面带着以上问题,通过示例代码来分析spring Aop源码

示例代码

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 (
  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值