ConditionalOnProperty
时间: 2023-07-12 10:00:57 浏览: 82
`ConditionalOnProperty` 是 Spring Boot 中的一个注解,用于根据配置文件中的属性值来决定是否启用某个 Spring Bean。通过设置 `name` 和 `havingValue` 参数,可以指定属性的名称和值,若该属性值与指定的值相等,则启用该 Bean;否则不启用。此外,还可以设置 `matchIfMissing` 参数,表示当配置中未指定该属性时,是否启用该 Bean。
相关问题
conditionalonproperty
@ConditionalOnProperty是Spring Boot中的一个条件注解之一,用于根据配置文件中的属性值来判断是否满足条件从而决定某个Bean或配置类是否生效。该注解可以通过配置文件中的属性值与给定的值进行比较,如果相等则生效,否则失效。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [SpringBoot教程(7) @ConditionalOnProperty 详细讲解和示例](https://blog.csdn.net/winterking3/article/details/114822929)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [SpringBoot - @ConditionalOnProperty注解使用详解](https://blog.csdn.net/goodjava2007/article/details/125536719)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
ConditionalOnProperty参数
ConditionalOnProperty参数是用来配置条件注解@ConditionalOnProperty的属性值。根据引用,当learn.conditionalOnProperty.enabled=false时,testValueProperty()方法不再执行。根据引用,当learn.conditionalOnProperty.enabled=false时,testNameProperty()方法不再执行。因此,ConditionalOnProperty参数的值应该是learn.conditionalOnProperty.enabled。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [@ConditionalOnProperty的用法以及处理@ConditionalOnProperty的源码分析](https://blog.csdn.net/qq_33790670/article/details/108800037)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文