Allow @ConditionalOnProperty NOT to match if the property value is empty

See original GitHub issue

In 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wilkinsonacommented, May 7, 2019

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 @ConditionalOnProperty to enable it so that you could opt in and so that existing use of @ConditionalOnProperty would be unaffected.

You have a couple of options with what’s currently available:

  1. Use havingValue to restrict the value that the condition will match
  2. Set the property value to false

If 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.

0reactions
wilkinsonacommented, May 8, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found