Allow @ConditionalOnProperty NOT to match if the property value is empty
See original GitHub issueIn my opinion @ConditionalOnProperty should be behave like @ConditionalOnExpression("!'${some.property:}'.empty")
If property is present but value is empty should be equal like there’s no property or at least there should be a flag which enables such behaviour
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
SpEL @ConditionalOnProperty string property empty or nulll
I know this condition checks on boolean but is there anyway to check if the string property is empty or null? DatabaseConfig.java @Configuration ......
Read more >The Spring @ConditionalOnProperty Annotation - Baeldung
In short, the @ConditionalOnProperty enables bean registration only if an environment property is present and has a specific value.
Read more >ConditionalOnProperty (Spring Boot 3.0.0 API)
The havingValue() and matchIfMissing() attributes allow further customizations. ... Specify if the condition should match if the property is not set.
Read more >SpEL @ConditionalOnProperty string property empty or nulll ...
As I undestood, you'r looking for "property exists and not empty" condition. This condition doesn't come out of the box, therefore some coding...
Read more >Spring @ConditionalOnProperty Example - Roy Tutorials
Here I will create examples on Spring conditional on property using the ... By default, any property that exists and is not equal...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We can’t change the current behaviour to match your expectation as it would be a breaking change. To provide the behaviour that you want, we would have to add an attribute to
@ConditionalOnPropertyto enable it so that you could opt in and so that existing use of@ConditionalOnPropertywould be unaffected.You have a couple of options with what’s currently available:
havingValueto restrict the value that the condition will matchfalseIf these don’t meet your needs then a custom condition may be your best option as I am still not convinced that we want the added complexity of another attribute.
Thanks again for the suggestion. We’ve discussed this today and the team’s opinion is that we don’t want the extra complexity of an additional attribute. To get the functionality that you want, you should write a custom condition as described in the Stack Overflow issue to which you have linked above.