Set Spring boot yaml configuration list property via environment variables
Asked Answered
C

1

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.

Conjunctive answered 30/1, 2017 at 15:17 Comment(0)
K
6

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

Knoxville answered 30/1, 2017 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.