2

I'm trying to register an autoconfiguration with @ConditionalOnProperty. This configuration should be created when there is any property with a predefined prefix.

For example, this configuration should be created when there is one of the properties listed below

test.property.any-text-goes-here.some-nested-property=test
test.property.nested.nested-two=another

I've tried to use @ConditionalOnProperty with name=test.property, but it doesn't seem to be working. Maybe this can be sorted out using @ConditionalOnExpression, but I have no idea how SpEL expression should look like.

I'm wondering if there a way to achieve this without the need of implementing custom Condition.

Thanks for your help!

geobreze
  • 2,274
  • 1
  • 10
  • 15
  • It's not possible without creating a custom `Condition`. This can also help you https://stackoverflow.com/questions/51257432/spring-conditionalonproperty-havingvalue-value1-or-value2?answertab=active#tab-top – Marcos Barbero Jul 29 '21 at 08:39

1 Answers1

0

Unfortunately, it is not possible. @ConditionalOnProperty evaluates and compares only final property values in flat structure. It does not work on objects :(

Michal
  • 550
  • 7
  • 14