8

I am configuring my Spring Boot application with an application.yml file:

foo:
  bar: foobar
foolist:
- bar: foobar1
  baz: foobaz1
- bar: foobar1
  baz: foobaz1

I can easily set the foo.bar value with an environment variable, e.g.

export FOO_BAR=value

How can I set values of the foolist entrie? FOOLIST[0]_BAR is not a valid identifier and FOOLIST_0_BAR does not work.

feob
  • 1,930
  • 5
  • 19
  • 31

1 Answers1

5

It's possible to provide arbitrary JSON object in the SPRING_APPLICATION_JSON environment variable:

export SPRING_APPLICATION_JSON='{"foolist":[{"bar": "foobar1", "baz: foobaz1"}, {"bar": "foobar2", "baz: foobaz2"}]}'

Documentation is here: https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/boot-features-external-config.html

Slava Semushin
  • 14,904
  • 7
  • 53
  • 69