Spring-boot: Make @ConditionalOnProperty @Repeatable

Created on 24 Feb 2015  路  11Comments  路  Source: spring-projects/spring-boot

I have a class that requires a couple of configuration properties to be set in order to instantiate a service, and also an enabled flag to turn off that autoconfig. While I'd like a simpler setup (#2312), in the meantime I'm trying to use @ConditionalOnProperty to check whether the properties are available. Since enabled defaults to true, I want it to matchIfMissing, but obviously not the other actual configuration properties.

However, matchIfMissing (and havingValue) apply to all of the properties in the annotation. I would like to be able to repeat the annotation to specify multiple property names that have different presence/value matching parameters.

blocked enhancement

Most helpful comment

It would be nice if this feature would come soon. It is much more easier to use multiple @ConditionalOnProperty

All 11 comments

Have you seen AnyNestedCondition? It's obviously not as nice as @Repeatable, but it's at least there for 1.2.

In this case, I'd need an AllNestedCondition.

Ahh OK. Good point. We do have a PR for that but it won't be looked at until 1.3 (see #2400). I like the repeatable idea as well.

Should this be a logical OR or an AND?

@benneq My take is that it should be a logical and so that it works in the same way as @Conditional.value()

It would be nice if this feature would come soon. It is much more easier to use multiple @ConditionalOnProperty

+1

vote vote +1

obviously +1

This requires a core framework change that still needs to be discussed. I've raised SPR-17207.

+1

Was this page helpful?
0 / 5 - 0 ratings