Properties to environment variables
Paste the keys from application.properties and get the form you need for a container, a shell or a deployment manifest. Everything runs in your browser, so a config that still holds credentials is safe to paste.
One key, every spelling
Type a property name to see each form Spring's relaxed binding accepts for it.
| Form | Name | Notes |
|---|
The rule people get wrong
Spring Boot converts a property name to an environment variable in three steps:
- Replace every dot (
.) with an underscore - Remove every dash (
-) - Uppercase the result
Step two is the one that bites. A dash is deleted, not turned into an underscore. So server.servlet.context-path binds fromSERVER_SERVLET_CONTEXTPATH — andSERVER_SERVLET_CONTEXT_PATH silently binds nothing at all, because Spring reads it as server.servlet.context.path.
Nothing fails loudly when this goes wrong. The application starts, the property keeps its default, and you find out later. If a variable seems to be ignored, this is the first thing to check.
List indices
Brackets become underscores too, so my.servers[0] reads fromMY_SERVERS_0 and app.users[1].name fromAPP_USERS_1_NAME.
Which source wins
When the same key is set in more than one place, Spring Boot takes the highest of these (later entries override earlier ones):
| Priority | Source |
|---|---|
| 1 (lowest) | application.properties inside the jar |
| 2 | application-{profile}.properties |
| 3 | Config files beside the jar |
| 4 | OS environment variables |
| 5 | SPRING_APPLICATION_JSON |
| 6 | Java system properties (-D) |
| 7 (highest) | Command-line arguments (--key=value) |
This is why a stray environment variable in a deployment manifest quietly beats the value in your properties file, and why --key=value is the reliable way to override something for a single run.
SPRING_APPLICATION_JSON
Passing many properties as individual variables gets unwieldy in a manifest. Spring Boot reads a whole config tree from one variable holding JSON, which keeps dashes and casing intact because the names are never mangled:
SPRING_APPLICATION_JSON='{"server":{"port":8080}}'It sits below system properties and command-line arguments in the order above.