javaspringspring-bootspring-properties

With Spring Boot and PropertySourcesPlaceholderConfigurer, how to resolve nested Properties?


I have a Spring Boot application.

I am including multiple dependencies, which have different PropertySourcesPlaceholderConfigurer configured.

One PropertySourcesPlaceholderConfigurer is reading Properties from a custom .properties file with a prefix like myResolver.

The file looks like this:

property.one=apple
property.two=${property.one}tree

I can inject both properties with $myResolver{property.one} correctly into my code.

However, when injecting $myResolver{property.two}, it gets injected as ${property.one}tree. ${property.one} is not resolved to apple.

How can I make Spring resolve nested properties inside properties files?


Solution

  • It seems that I need to write property.two=$myResolver{property.one}tree to resolve the nested property.

    The prefix is important.