配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效

1、matchIfMissing属性:从application.properties中读取某个属性值,如果该值为空,默认值为true

@Configuration
@ConditionalOnClass({ Feign.class })
@ConditionalOnProperty(value = "feign.oauth2.enabled", 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中读取某个属性值,如果该值为空,则返回false;如果值不为空,则将该值与havingValue指定的值进行比较,如果一样则返回true;否则返回false。如果返回值为false,则该configuration不生效;为true则生效。

@Configuration
//如果synchronize在配置文件中并且值为true
@ConditionalOnProperty(name = "synchronize", havingValue = "true")
public class SecondDatasourceConfig { @Bean(name = "SecondDataSource")
@Qualifier("SecondDataSource")
@ConfigurationProperties(prefix = "spring.second.datasource")
public DataSource jwcDataSource() {
return DataSourceBuilder.create().build();
}
}

ConditionalOnProperty的更多相关文章

  1. Spring ConditionalOnProperty

    Spring Annotation @ConditionalOnProperty spring doc解释 @Conditional: Indicates that a component is on ...

  2. @ConditionalOnProperty 详解

    @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @Documented @Con ...

  3. 配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效

    Spring boot中有个注解@ConditionalOnProperty,这个注解能够控制某个configuration是否生效. 具体操作是通过其两个属性name以及havingValue来实现 ...

  4. What is purpose of @ConditionalOnProperty annotation?

    http://stackoverflow.com/questions/26394778/what-is-purpose-of-conditionalonproperty-annotation **** ...

  5. @ConditionalOnProperty来控制Configuration是否生效

    1. 简介 Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效 2. 说明 @Retention(RetentionPolicy.RUNTI ...

  6. @ConditionalOnProperty注解

    一 源码解析 查看ConditionalOnProperty的源码 package org.springframework.boot.autoconfigure.condition; import j ...

  7. Spring Boot中@ConditionalOnProperty使用详解

    在Spring Boot的自动配置中经常看到@ConditionalOnProperty注解的使用,本篇文章带大家来了解一下该注解的功能. Spring Boot中的使用 在Spring Boot的源 ...

  8. @Conditional 和 @ConditionalOnProperty

    @ConditionalOnProperty https://blog.csdn.net/dalangzhonghangxing/article/details/78420057 @Condition ...

  9. Springboot @ConditionalOnProperty注解

    最近看了一段代码其中用到了@ConditionalOnProperty注解,直接没有了解过这个注解,今天看到了顺便了解一下 具体代码如下 @Configuration public class Web ...

随机推荐

  1. Flink--sink到kafka

    package com.flink.DataStream import java.util.Properties import org.apache.flink.api.common.serializ ...

  2. python--类中的对象方法、类方法、静态方法的区别

    1.对象方法:顾名思义,是对类实例化后的对象有效的,由对象调用 2.类方法:第一个参数是cls(当前类),是对当前类做的额外的处理,类方法需要用类去调用,而不是实例对象调用 3.静态方法:没有参数!没 ...

  3. YII框架增删改查常用语句

    //实例化db $db = new \yii\db\Query(); //插入 $db->createCommand()->insert('user', [ 'name' => 't ...

  4. Substrings kmp

    Problem Description You are given a number of case-sensitive strings of alphabetic characters, find ...

  5. mybatis提示Invalid bound statement (not found)错误的可能原因

    https://www.cnblogs.com/liaojie970/p/8034525.html

  6. Eight (HDU - 1043|POJ - 1077)(A* | 双向bfs+康拓展开)

    The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've see ...

  7. Stm32串口通信(USART)

    Stm32串口通信(UART) 串口通信的分类 串口通信三种传递方式 串口通信的通信方式 串行通信的方式: 异步通信:它用一个起始位表示字符的开始,用停止位表示字符的结束.其每帧的格式如下: 在一帧格 ...

  8. Qt创建任务栏进度条

    一.正文 任务栏进度条是Windows7就引入的一种UI形式,通常用于显示软件当前正在执行的任务的进度(如编译程序的进度.下载任务的进度).如下: 在Qt中使用任务栏进度条也是非常容易的一件事情.Qt ...

  9. [OC] @property时,copy、strong、weak、assign的区别

    @property(copy,nonatomic)NSMutableString*copyStr; @property(strong,nonatomic)NSMutableString*strongS ...

  10. C# 使用PrintDocument 绘制表格 完成 打印预览

    C# 使用PrintDocument 绘制表格 完成 打印预览 DataTable   经过不断的Google与baidu,最终整理出来的打印类 主要是根据两个参考的类组合而成,稍微修改了一下,参考代 ...