@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接口结构

Interceptor
:大概对应@Around
BeforeAdvice
:大概对应@Before
AfterAdvice
:大概对应@After
AfterReturningAdvice
:大概对应@AfterReturning
ThrowsAdvice
:大概对应@AfterThrowing
这里我是说大概对应,后面看到AspectJ具体实现时,可能有些许不同
这里复习一下执行顺序接下来我们再添2个类
MethodInterceptor
:定义了接口方法MethodBeforeAdvice
:定义了接口方法
AspectJ的通知实现
我们先把下面的几个通知混个脸熟
-
AspectJMethodBeforeAdvice
:对应@Before
-
AspectJAroundAdvice
:对应@Around
-
AspectJAfterAdvice
:对应@After
-
AspectJAfterReturningAdvice
:对应@AfterReturning
-
AspectJAfterThrowingAdvice
:对应@AfterThrowing
总结
这篇主要和大家分享下通知对应的实现类。
原文始发于微信公众号(溪溪技术笔记):SpringAOP源码阅读-Advice
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/207153.html