我有方面要做一些事情,但是我需要能够在.properties文件中将其禁用。我使用解决方案here尝试了@ConditionalOnExpression
...
@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");
}
}
没有任何效果。 如何至少通过application.properties或任何其他.properties文件标志禁用adviceMethod的执行?