本文介绍了如何在使用@ConditionalOnProperty或@ConditionalOnExpression时检查两个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在创建bean时,我需要检查YAML属性文件上是否满足两个条件.我该怎么做,因为@ConditionalOnProperty
批注仅支持一个属性?
I need to check that two conditions are satisfied on a YAML property file, while creating a bean. How do I do that, as the @ConditionalOnProperty
annotation supports only one property?
推荐答案
从@ConditionalOnProperty
开始,就可以检查多个属性.名称/值属性是一个数组.
Since from the beginning of @ConditionalOnProperty
it was possible to check more than one property. The name / value attribute is an array.
@Configuration
@ConditionalOnProperty({ "property1", "property2" })
protected static class MultiplePropertiesRequiredConfiguration {
@Bean
public String foo() {
return "foo";
}
}
对于带有AND检查的简单布尔属性,不需要@ConditionalOnExpression
.
For simple boolean properties with an AND check you don't need a @ConditionalOnExpression
.
这篇关于如何在使用@ConditionalOnProperty或@ConditionalOnExpression时检查两个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!