How to check two condition while using @ConditionalOnProperty or @ConditionalOnExpression

后端 未结 4 1355
面向向阳花
面向向阳花 2020-12-14 16:50

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 sup

4条回答
  •  粉色の甜心
    2020-12-14 17:33

    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";
        }
    
    }
    

    For simple boolean properties with an AND check you don't need a @ConditionalOnExpression.

提交回复
热议问题