欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SpringAop方法执行顺序

程序员文章站 2022-05-08 17:41:15
...

SpringAop方法执行顺序

  1. BeforeAround
  2. before
  3. 实际方法
  4. AfterReturn
  5. After
  6. AfterAround
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 青韵
 * @date 2020/9/2 - 9:21
 */
@Component
@Aspect
@Order(2)
public class AopTest {
    @Pointcut("execution(public void aop.Test.*(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void before() {
        System.out.println("before...");
    }

    @AfterReturning("pointCut()")
    public void afterReturn() {
        System.out.println("after.return...");
    }

    @After("pointCut()")
    public void after() {
        System.out.println("after...");
    }

    @AfterThrowing("pointCut()")
    public void aftThr() {
        System.out.println("出错");
    }

    @Around("pointCut()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("before around----");
        joinPoint.proceed();
        System.out.println("after around----");
    }
}

SpringAop方法执行顺序

相关标签: Java aop