ConditionalOnProperty
鲲鱼
惊涛拍岸配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否⽣效
耳垂厚>肺动脉压正常值
1、matchIfMissing属性:从application.properties中读取某个属性值,如果该值为空,默认值为true
破费@Configuration
@ConditionalOnClass({ Feign.class })
@ConditionalOnProperty(value = "abled", matchIfMissing = true)
public class OAuth2FeignAutoConfiguration {
@Bean
@ConditionalOnBean(OAuth2ClientContext.class)
public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oauth2ClientContext) {
return new OAuth2FeignRequestInterceptor(oauth2ClientContext);
诟骂}
}
2、havingValue属性:通过其两个属性name以及havingValue来实现的,其中name⽤来从application.properties中读取某个属性值,如果该值为空,则返回fal;如果值不为空,则将该值与havingValue指定的值进⾏⽐较,如果⼀样则返回true;否则返回fal。如果返回值
为fal,则该configuration不⽣效;为true则⽣效。
@Configuration
//如果synchronize在配置⽂件中并且值为true
阳虚山
@ConditionalOnProperty(name = "synchronize", havingValue = "true")
public class SecondDatasourceConfig {
@Bean(name = "SecondDataSource")
@Qualifier("SecondDataSource")
小海兔的故事
@ConfigurationProperties(prefix = "d.datasource")
public DataSource jwcDataSource() {
ate().build();
}
}