Spring_20-21,切面的优先级&重用切点表达式

来源:互联网 发布:算法设计与分析第二版 编辑:程序博客网 时间:2024/06/05 14:07
//使用@Order声明切面的优先级,数字越小优先级越大,比如验证优先于日志@Order(2)//声明为切面@Aspect@Componentpublic class LoggingAspect
/**     * 定义一个方法, 用于声明切入点表达式. 一般地, 该方法中再不需要添入其他的代码.      * 使用 @Pointcut 来声明切入点表达式.      * 后面的其他通知直接使用方法名来引用当前的切入点表达式.      */    @Pointcut("execution(* com.hgh.spring.aop.annotation.ArithmeticCalculator.*(..))")    public void loggingPointcut(){}    //前置通知    //@Before("execution(public int com.hgh.spring.aop.annotation.ArithmeticCalculator.*(..))")    @Before("loggingPointcut()")    public void beforeMethod(JoinPoint joinPoint){        String methodName = joinPoint.getSignature().getName();        Object[] args = joinPoint.getArgs();        System.out.println("the method "+methodName+"Before with"+Arrays.asList(args));    }
0 0
原创粉丝点击