参考: https://blog.csdn.net/u010002184/article/details/79353696
https://blog.csdn.net/weixin_37226516/article/details/104159549
本人当前使用场景: 利用切面打印日志,开发环境使用, 生产环境下关闭;
@Aspect
@Component
@ConditionalOnProperty(name = "task.switch", havingValue = "true")
@Slf4j
public class AnnotationLogAspect {
....
}
yml文件中配置
task:
switch: true
当 task.switch = true 时bean会注入切面日志启动
当 task.switch 不等于 true时 bean无法注入
从而实现了使用配置控制bean是否注入