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

 

posted @ 2017-12-11 14:23  寻找风口的猪  阅读(1793)  评论(0编辑  收藏  举报