Spring Boot - autoconfigure if any property with prefix exists

890 Views Asked by At

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!

1

There are 1 best solutions below

0
On

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