5

I have webbapp based on Spring. To configure it I use .yml files. To convert environmental variable from spring/backend .yml format to docker-compose.yml environment section I have to change indents into underscores. Example:

application.yml

spring:
  mail:
    properties.mail.smtp:
      auth: true

docker-compose.yml

    environment:
      SPRING_MAIL_PROPERTIES.MAIL.SMTP_AUTH: true

But some property names contain underscores itself. Like this:

spring:
  jpa:
    properties:
      hibernate:
        temp:
          use_jdbc_metadata_defaults: false

How should I translate such properties (with underscores in names) to the environment section in docker-compose.yml?

This question is not a duplicate. Mentioned similar question does not answer my question. Question How to set a Spring Boot property with an underscore in its name via Environment Variables? is about how to represent properties with underscores in Spring Boot and accepted answer shows how property file entry is interpreted by Spring. There is a link to SystemEnvironmentPropertySource.java class which is responsible for translation and interpretation of properties in Spring. My question asks about .yml file interpretation in Docker-Compose. So I need basically similar answer to the accepted one in the mentioned thread but about how Docker-Compose interprets .yml properties to environment variables.

luke
  • 3,435
  • 33
  • 41
  • 1
    Have you ever found a solution for that issue? I have the same scenario with spring.jpa.properties.hibernate.criteria.literal_handling_mode=BIND that I want to inject via ENV settings. The underscores in the ENV settings become dots and the config is not picked up – hecko84 May 11 '20 at 14:29
  • Unfortunately I haven't. – luke Jun 19 '20 at 21:29
  • @luke You can pass it as JSON with the environment variable `SPRING_APPLICATION_JSON`, see https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config – Elepferd Jul 20 '20 at 08:42

0 Answers0