SpringAOP源码阅读-Advice

@Aspect
public class XiXiAspect {
    @Pointcut("execution(public * *(..))")
    public void pointCut(){
    }
    @Before("pointCut()")
    public void before(){
        System.out.println("aspectJ before");
    }
    @After("pointCut()")
    public void after(){
        System.out.println("aspectJ before");
    }
    @AfterReturning("pointCut()")
    public void afterReturning(){
        System.out.println("aspectJ before");
    }
    @AfterThrowing("pointCut()")
    public void afterThrowing(){
        System.out.println("aspectJ before");
    }
    @Around("pointCut()")
    public void around(ProceedingJoinPoint proceedingJoinPoint){
        System.out.println("aspectJ before");
    }
}

上面写了5种通知。对应在代码中它是如何映射的

Advice接口结构

SpringAOP源码阅读-Advice
image.png

Interceptor:大概对应@AroundBeforeAdvice:大概对应@BeforeAfterAdvice:大概对应@AfterAfterReturningAdvice:大概对应@AfterReturningThrowsAdvice:大概对应@AfterThrowing这里我是说大概对应,后面看到AspectJ具体实现时,可能有些许不同

这里复习一下执行顺序SpringAOP源码阅读-Advice接下来我们再添2个类SpringAOP源码阅读-Advice

  • MethodInterceptor:定义了接口方法
  • MethodBeforeAdvice:定义了接口方法

AspectJ的通知实现

SpringAOP源码阅读-Advice我们先把下面的几个通知混个脸熟

  • AspectJMethodBeforeAdvice:对应@Before
  • AspectJAroundAdvice:对应@Around
  • AspectJAfterAdvice:对应@After
  • AspectJAfterReturningAdvice:对应@AfterReturning
  • AspectJAfterThrowingAdvice:对应@AfterThrowing

总结

这篇主要和大家分享下通知对应的实现类。


原文始发于微信公众号(溪溪技术笔记):SpringAOP源码阅读-Advice

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/207153.html

(0)
小半的头像小半

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!