Ad

Spring Boot + Docker Compose: How To Override 'Map>' Environment Variable From Yaml Properties

I am using yaml properties file for the sping boot configuration.

My structure of application.yml is following:

information:
  server: ${SERVER_INFO:devserver}
  config:
    "[http://www.myshop.com]":
      - Sam
      - Joe
    "[https://www.google.com]":
      - Mary
   ... other properties of Map type.

All this values basically represent structure Map<String, List<String>> where key is site address and List is a array of the users. There could be many entries of this map, I am using this structure to read properties dynamicly.

How my docker container looks:

app:
  ports:
    - "8080:8080"
  build:
    ... i will skip this info
  image: testapp
  environment:
    - SERVER_PORT=8080
    - SERVER_INFO=QAAserver // overrided sucessfully
    - INFORMATION_CONFIG=?? // how to pass Map<Sting, List<String>> here?

So, basically, I need an ability to pass values of Map<String, List<String>> from docker compose env var to the spring boot, to override current value. How can I do it?

Ad

Answer

JSON Objects are Map<String, Object> values.

    INFORMATION_CONFIG='{"[http://www.myshop.com]": ["Sam", "Joe"], "[https://www.google.com]": ["Mary"]}'

But you may want to use SPRING_APPLICATION_JSON for this

https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.application-json

Ad
source: stackoverflow.com
Ad