对于Spring-AOP使用不同层级多个切点表达式,但是切入同一个方法的切入顺序探讨

博主脑子短路的操作

今天在研究aop的时候发现了一种神奇的情况:

首先,包结构如下:
在这里插入图片描述
包结构下有com.yankaizhang.aoptest.controller.Test.show()方法

情况1

想要分别在三个不同层级下,对show方法进行切入操作,三个层次的切面表达式如下:

  1. com.yankaizhang.aoptest.controller.Test1.*
  2. com.yankaizhang.aoptest.controller.*.*
  3. com.yankaizhang.aoptest.*.*.*

于是我写了一个切点类:

@Aspect
@Component
public class LogAspect {
   

    @Before("execution(* com.yankaizhang.aoptest.controller.Test1.*(..))")
    public void before1(){
   
        System.out.println("before1");
    }

    @Before("execution(* com.yankaizhang.aoptest.controller.*.*(..))")
    public void before2(){
   
        System.out.println("before2");
    }

    @Before("execution(* com.yankaizhang.aoptest.*.*.*(..))")
    public void before3(){
   
        System.out.println("before3");
    }

    @AfterReturning("execution(* com.yankaizhang.aoptest.controller.Test1.*(..))")
    public void after1(){
   
        System.out.println("after1");
    }

    @AfterReturning("execution(* com.yankaizhang.aoptest.controller.*.*(..))")
    public void after2(){
   
        System.out.println("after2");
    }

    @AfterReturning
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值