I used spring-boot-starter-parent 2.7.4
to test the execution sequence of @Around @Before @After @AfterReturning,here is what I got: (The method of my point cut is to print "hello, world")
If I do not use @Around advice:
before ......
hello, world
afterReturning ......
after ......
If I use @Around advice:
around before......
before ......
hello, world
afterReturning ......
after ......
around after......
According to the Internet, the sequence should be:around before -> before -> join point method -> around after -> after -> after returning
Why in my result, afterReturning
went ahead of after
, and around after
went to the end?
My @Aspect code
@Aspect
@Component
public class MyAspect {
@Pointcut("execution(* com.example.springboot_test_1005.Dog.bark(..))")
public void pointCut() {
}
@Before("pointCut()")
public void before() {
System.out.println("before ......");
}
@After("pointCut()")
public void after() {
System.out.println("after ......");
}
@AfterReturning("pointCut()")
public void afterReturning() {
System.out.println("afterReturning ......");
}
@AfterThrowing("pointCut()")
public void afterThrowing() {
System.out.println("afterThrowing ......");
}
@Around("pointCut()")
public void around(ProceedingJoinPoint jp) throws Throwable {
System.out.println("around before......");
jp.proceed();
System.out.println("around after......");
}
}
@Component
public class Dog {
void bark(){
System.out.println("hello, world");
}
}