美文网首页
自定义@Configuration配置类启用开关

自定义@Configuration配置类启用开关

作者: _花 | 来源:发表于2022-04-12 16:59 被阅读0次

利用@ConditionalOnProperty

通过其两个属性name以及havingValue来实现的,其中name用来从application.yml中读取某个属性值。
如果该值为空,则返回false;
如果值不为空,则将该值与havingValue指定的值进行比较,如果一样则返回true;否则返回false。
如果返回值为false,则该configuration不生效;为true则生效。
在配置类上新加注解@ConditionalOnProperty

@ConditionalOnProperty(name = "uuap.enable", havingValue = "true")
//或者@ConditionalOnProperty(name = "uuap.enable")
@Configuration
public class UuapConfig {}

在application.yml文件添加配置

uuap:
  enable: false

相关文章

网友评论

      本文标题:自定义@Configuration配置类启用开关

      本文链接:https://www.haomeiwen.com/subject/oxrnsrtx.html