spring-boot
spring-boot copied to clipboard
Allow more configuration for ConditionalOnProperty
I was wanting to make use of @ConditionalOnProperty in a project recently and expected it to evaluate false if the value of the property was null, however it seems that the condition only evaluates false if the property is completely missing, or it's set to the string value false
What I want to propose is that we add another option to the annotation like follows
String[] notHavingValues() default { "false" };
and then in OnPropertyCondition::isMatch we can check against this rather than the hardcoded false value.
For my use case I could then annotate my bean definition as so, whilst also not breaking backwards compatibility
@Bean
@ConditionalOnProperty(name = "my.property", notHavingValues = { "", null })
public Widget widget() {
return new Widget();
}
Happy to raise a PR, but wanted to get feedback first - thanks for your consideration!
Alternative workarounds are to use a ConditionalOnExpression and write spel