項目中有兩個切面,這兩個切面都作用於同一個方法,哪個先執行哪個后執行呢,所以要定義一個切面的優先級
import java.util.Arrays; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; /** * 可以使用 @Order 注解指定切面的優先級, 值越小優先級越高 */ @Order(1) @Aspect @Component public class VlidationAspect { @Before("execution(public double com.spring2.lee.aop.impl.*.*(..))") public void validateArgs(JoinPoint joinPoint){ System.out.println("-->validate:" + Arrays.asList(joinPoint.getArgs())); } }
@Order(2) @Aspect @Component public class LoggingAspect { ... }