SpringAOP-切面優先級


項目中有兩個切面,這兩個切面都作用於同一個方法,哪個先執行哪個后執行呢,所以要定義一個切面的優先級

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 {
...
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM