EngineerBetter EngineerBetter - 9 months ago 104
Java Question

How to set a Spring Boot property with an underscore in its name via Environment Variables?

I want to set

in a Spring Boot app. I want to set it using environment variables.

Spring Boot rather handily converts all environment variables from, for example,
to properties called
inside the Spring context.

How can I set a property that has an underscore in the target name, in Spring Boot, using environment variables? Presumably
will be translated to

Max Max
Answer Source

This is an old question but I'll answer it in case sombebody else (like me) ends up here looking for this information.

HIBERNATE_FORMAT_SQL should do the trick

Actually it is not the OS environment variable that is "translated" but rather the Spring property name that is.

The name is translated in several ways and looked up against available environment variables. E.g. "hibernate.format.sql" is looked up as:

  1. hibernate.format.sql (as is)
  2. hibernate_format_sql (dots replaced with underscores)
  3. hibernate_format_sql (dashes replaced with underscores, the same in your case)
  4. hibernate_format_sql (dashes & dots replaced with underscores, the same in your case)

Then the same with UPPERCASE:

  2. HIBERNATE_FORMAT_SQL (dots replaced with underscores)
  3. HIBERNATE_FORMAT_SQL (dashes replaced with underscores, the same again)
  4. HIBERNATE_FORMAT_SQL (dashes & dots replaced with underscores, the same again)

Although you cannot set an environment variable with a dot in the name with the set or export commands it is however possible with the env command. I defer judgement whether this is a good idea or not:

env "\"a value\"" the-command-you-want-to-run

Have a look at for details. I link to a specific version but you should make sure to look at the version you are using.

To troubleshoot these kinds of problems in a production environment you could try turning on debug logging for the property resolving code:

    org.springframework.core.env: DEBUG

... or by setting the appropriate environment variable :)