关于@ConfigurationProperties注解全解析
@ConfigurationProperties注解解析
@ConfigurationProperties注解类似于@value 可以将application中的配置映射到java变量中 通过@ConfigurationProperties,可以配置是否加载bean
示例
application.yml
spring:
complex: #重量级模式是否开启 在线上可以不加载开发环境bean
enable: trueConfigProperties 配置是否加载的标识 加载为true
不加载为fasle 对应上文配置
@ConfigurationProperties(prefix = "spring.complex")
public class ConfigProperties {
private boolean enable;
public boolean isEnable() {
return enable;
}
public void setEnable(boolean enable) {
this.enable = enable;
}
}通过@EnableConfigurationProperties指定上文配置的标识
并通过@ConditionalOnProperty判断 下文实现
如果application里面配置的为false或者不配置(默认为false)则swagger相关配置不会加载 提高启动速度
@Configuration(proxyBeanMethods = false)
@EnableSwagger2
@EnableConfigurationProperties(ConfigProperties.class)
@ConditionalOnProperty(prefix = "spring.complex", name = "enable", havingValue = "true", matchIfMissing = false) 指定通过spring.complex.enable属性判断 如果为true 则加载 默认为false
public class SwaggerConfig{
}总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Spring探秘之如何妙用BeanPostProcessor
BeanPostProcessor也称为Bean后置处理器,它是Spring中定义的接口,在Spring容器的创建过程中会回调BeanPostProcessor中定义的两个方法,这篇文章主要给大家介绍了关于Spring探秘之如何妙用BeanPostProcessor的相关资料,需要的朋友可以参考下2022-01-01
java使用短信设备发送sms短信的示例(java发送短信)
这篇文章主要介绍了java使用短信设备发送sms短信的示例(java发送短信),需要的朋友可以参考下2014-04-04
SpringBoot项目集成Swagger和swagger-bootstrap-ui及常用注解解读
这篇文章主要介绍了SpringBoot项目集成Swagger和swagger-bootstrap-ui及常用注解解读,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-03-03


最新评论