可以使用@Order 注解指定切面的优先级,值越小优先级越高
/* * 可以使用@Order 注解指定切面的优先级,值越小优先级越高 * */ @Order(2) @Component @Aspect public class LoggingAspect { /** * 在每一个接口的实现类的每一个方法开始之前执行一段代码 */ @Before("execution(public int com.atguigu.spring.aop.ArithmeticCalculator.* (..))") public void beforeMethod(JoinPoint joinPoint){ String methodName = joinPoint.getSignature().getName(); Object[] args = joinPoint.getArgs(); System.out.println("The method "+methodName+" begins with "+ Arrays.asList(args)); } }
@Order(1) @Aspect @Component public class VlidationAspect { @Before("execution(public int com.atguigu.spring.aop.ArithmeticCalculator.* (..))") public void validateArgs(JoinPoint joinPoint){ System.out.println("------->validate:" + Arrays.asList(joinPoint.getArgs())); } }
原文:https://www.cnblogs.com/xjs1874704478/p/12025282.html