I'm trying to reuse an Environment variable in a YAML file. The problem is that I need to use the value of the Environment variable if exists or a default value. But this default value varies in different places of the configuration.
For instance, I can do this:
urls:
url1: ${BASE_URL:http://1}
url2: ${BASE_URL:http://2}
... And so on.
But what I want to do is:
urls:
base: ${BASE_URL}
url1: ${urls.base:http://1}
url2: ${urls.base:http://2}
The problem is that in the latter approach if the Environment variable is not set then property urls.base will have this string "${BASE_URL}" as value so the default values will not be used
If I set a default empty value to the urls.base property then url1 and url2 will be empty and no default values will be used.
Other reasons other than reusing the environment variable are:
- Better name
- Execute logic if the variable exists and does not have an empty value
PD: I'm using Spring boot