2

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

Anthon
  • 69,918
  • 32
  • 186
  • 246
JJ Yong
  • 63
  • 9
  • 2
    There is no such functionaltiy in YAML, `${BASE_URL}` is just a normal scalar. Any functionality to replace that with or without some default value comes from the program **before or after loading the YAML document**. – Anthon Feb 12 '19 at 16:55
  • **See also:** [Use placeholders in YAML](https://stackoverflow.com/a/41620747/42223) – dreftymac Apr 11 '19 at 21:14

0 Answers0