// 对应的测试注入情况
@Configuration
@ConditionalOnProperty(value = "")
public class parentNameConfig {
}
.yml配置如下:
parentName:
sonName: true //正常
parentName:
sonName: //正常,空字符时
parentName:
sonName: false //失败
parentName:
sonName: null //正常
parentName:
sonName: 123 //正常
把第二行换成:
@ConditionalOnProperty(value = "",havingValue = "123")
.yml配置如下:
parentName:
sonName: 123 //正常
parentName:
sonName: 1234 //失败
parentName:
sonName: false //失败
把第二行换成:
@ConditionalOnProperty(value = "",havingValue = "false")
.yml配置如下:
parentName:
sonName: false //正常
把第二行换成:
@ConditionalOnProperty(prefix = "parentName",name = "sonName",havingValue = "123")
.yml配置如下:
parentName:
sonName: 123 //正常
parentName:
sonName: 1234 //失败,与havingValue给定的值不一致
把第二行换成:
@ConditionalOnProperty(prefix = "parentName",name = "sonName",havingValue = "123",matchIfMissing = true)
.yml配置如下:
不配置相关参数 //正常,当matchIfMissing = true时,即使没有该属性也会加载正常
把第二行换成:
@ConditionalOnProperty(prefix = "parentName",name = "sonName",havingValue = "123",matchIfMissing = false) //这里matchIfMissing默认为false,写不写都行
.yml配置如下:
不配置相关参数 //失败,当matchIfMissing = false时,必须要有对应的property
parentName:
sonName: 123 //正常
把第二行换成:
@ConditionalOnProperty(prefix = "parentName.", name = "sonName")//prefix带了.(点)
.yml配置如下:
parentName:
sonName: true //正常
parentName:
sonName: 123 //正常
把第二行换成:
@ConditionalOnProperty(prefix = "parentName",value = {"sonName2"},name = {"sonName"})
.yml配置如下:
parentName:
sonName: true //项目Debug启动失败,The name and value attributes of @ConditionalOnProperty are exclusive
//@ConditionalOnProperty的name和value属性是互斥的,不能同时出现
把第二行换成:
@ConditionalOnProperty(prefix = "parentName",name = {"sonName"})
.yml配置如下:
parentName:
sonName: true //正常
把第二行换成:
@ConditionalOnProperty(prefix = "parentName",name = {"sonName","flag"}) //name中的属性需要两个都存在且都不为false才会加载正常
.yml配置如下:
parentName:
sonName: true
flag: true //正常
parentName:
sonName: true
flag: 123 //正常
parentName:
sonName: true
flag: false //失败
parentName:
sonName: false
flag: false //失败
把第二行换成:
@ConditionalOnProperty(prefix = "parentName", name = {"sonName", "flag"}, havingValue = "false")
parentName:
sonName: false
flag: false //正常
把第二行换成:
@ConditionalOnProperty(prefix = "parentName", name = {"sonName", "flag"}, havingValue = "123")//和的值都要与havingValue的一致才行
parentName:
sonName: 123
flag: 1234 //失败
parentName:
sonName: 123
flag: 123 //正常
parentName:
sonName: 123 //失败,缺少
把第二行换成:
@ConditionalOnProperty(prefix = "parentName", name = {"sonName", "flag"}, havingValue = "123",matchIfMissing = true)//matchIfMissing = true允许缺少
parentName:
sonName: 123 //正常
.yml配置如下:
不配置相关参数 //正常
把第二行换成:
@ConditionalOnProperty(prefix = "parentName", name = {"sonName", "flag"}, havingValue = "123")
.yml配置如下:
不配置相关参数 //失败
相关文章
- @ConditionalOnProperty注解控制配置文件是否生效
- 配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效
- @ConditionalOnProperty注解详解
- Java如何对Map进行排序详解(map集合的使用)
- Spring框架引入@Aspect注解一直失败pom依赖问题解决
- 集合-TreeMap详解和TreeSet详解以及两者的区别
- testNg注解@BeforeSuite,@BeforeTest,@BeforeClass,@BeforeGroups,@AfterGroups,@BeforeMethod
- Spring AOP 针对注解的AOP
- JAVA 23种设计模式详解
- mybtais的mapper中使用@Select注解使用if