版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38409944/article/details/82701081
如果有两个切面,那么谁先谁后怎么判断?
那如果我们要指定切面的执行顺序呢?
可以使用@Order注解指定切面的优先级,值越小
优先级越高。
举例:
两个切面类:
@Order(2)
@Aspect
@Component
public class MyAspect {
@Before("execution(public * calculator.CalculatorImpl.*(..))")
public void before(JoinPoint joinPoint){
System.out.println("参数:"+Arrays.asList(joinPoint.getArgs()));
}
}
@Order(3)
@Aspect
@Component
public class MynewAspect {
@Before("execution(public * calculator.CalculatorImpl.*(..))")
public void before(JoinPoint joinPoint){
System.out.println("方法:"+joinPoint.getSignature().getName());
}
}
输出:
参数:[1, 2]
方法:add
执行add方法
3