代码之家  ›  专栏  ›  技术社区  ›  JiKra

禁用基于标志的方面

  •  0
  • JiKra  · 技术社区  · 8 年前

    我有方面做一些事情,但我需要能够禁用它我。属性文件。我试过了 @ConditionalOnExpression 使用溶液 here ...

    @Component
    @Aspect
    @ConditionalOnExpression("${enabled:false}")
    public class OtherAspect {
    
        @Pointcut("execution(* *(..))")
        public void methodExecution() {
        }
    
        @Before("methodExecution()")
        public void adviceMethod(JoinPoint joinPoint) {
            System.out.println("OtherAspect 1");
            if(true){
                System.out.println("OtherAspect 2");
            }
        }
    }
    

    我试过@Value()。。。

    @Component
    @Aspect
    public class OtherAspect {
    
        @Value("${performance.log.enabled:true}")
        private boolean enabled;
    
        @Pointcut("execution(* *(..))")
        public void methodExecution() {
        }
    
        @Before("methodExecution()")
        public void adviceMethod(JoinPoint joinPoint) {
            System.out.println("OtherAspect 1");
            if(enabled){
                System.out.println("OtherAspect 2");
            }
        }
    }
    

    我试过@Profile

    @Component
    @Aspect
    @Profile("enabled")
    public class OtherAspect {
    
        @Pointcut("execution(* *(..))")
        public void methodExecution() {
        }
    
        @Before("methodExecution()")
        public void adviceMethod(JoinPoint joinPoint) {
            System.out.println("OtherAspect 1");
        }
    }
    

    什么都没用。 如何至少禁用应用程序执行adviceMethod。财产或任何其他。属性文件标志?

    0 回复  |  直到 8 年前