Skip to content

Commit d27e437

Browse files
committed
Merge branch '2.1.x' into 2.2.x
Closes gh-21027
2 parents 55f0af7 + f0ec571 commit d27e437

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ You can provide default values for your application in `application.properties`
522522
These default values can then be overridden at runtime with a different file located in one of the custom locations.
523523

524524
NOTE: If you use environment variables rather than system properties, most operating systems disallow period-separated key names, but you can use underscores instead (for example, configprop:spring.config.name[format=envvar] instead of configprop:spring.config.name[]).
525+
See <<boot-features-external-config-relaxed-binding-from-environment-variables>> for details.
525526

526527
NOTE: If your application runs in a container, then JNDI properties (in `java:comp/env`) or servlet context initialization parameters can be used instead of, or as well as, environment variables or system properties.
527528

@@ -1093,9 +1094,8 @@ NOTE: The `prefix` value for the annotation _must_ be in kebab case (lowercase a
10931094
| Standard YAML list syntax or comma-separated values
10941095

10951096
| Environment Variables
1096-
| Upper case format with underscore as the delimiter.
1097-
`_` should not be used within a property name
1098-
| Numeric values surrounded by underscores, such as `MY_ACME_1_OTHER = my.acme[1].other`
1097+
| Upper case format with underscore as the delimiter (see <<boot-features-external-config-relaxed-binding-from-environment-variables>>).
1098+
| Numeric values surrounded by underscores (see <<boot-features-external-config-relaxed-binding-from-environment-variables>>)`
10991099

11001100
| System properties
11011101
| Camel case, kebab case, or underscore notation
@@ -1104,6 +1104,10 @@ NOTE: The `prefix` value for the annotation _must_ be in kebab case (lowercase a
11041104

11051105
TIP: We recommend that, when possible, properties are stored in lower-case kebab format, such as `my.property-name=acme`.
11061106

1107+
1108+
1109+
[[boot-features-external-config-relaxed-binding-maps]]
1110+
===== Binding Maps
11071111
When binding to `Map` properties, if the `key` contains anything other than lowercase alpha-numeric characters or `-`, you need to use the bracket notation so that the original value is preserved.
11081112
If the key is not surrounded by `[]`, any characters that are not alpha-numeric or `-` are removed.
11091113
For example, consider binding the following properties to a `Map`:
@@ -1123,6 +1127,32 @@ The properties above will bind to a `Map` with `/key1`, `/key2` and `key3` as th
11231127
NOTE: For YAML files, the brackets need to be surrounded by quotes for the keys to be parsed properly.
11241128

11251129

1130+
[[boot-features-external-config-relaxed-binding-from-environment-variables]]
1131+
===== Binding from Environment Variables
1132+
Most operating systems impose strict rules around the names that can be used for environment variables.
1133+
For example, Linux shell variables can contain only letters (`a` to `z` or `A` to `Z`), numbers (`0` to `9`) or the underscore character (`_`).
1134+
By convention, Unix shell variables will also have their names in UPPERCASE.
1135+
1136+
Spring Boot's relaxed binding rules are, as much as possible, designed to be compatible with these naming restrictions.
1137+
1138+
To convert a property name in the canonical-form to an environment variable name you can follow these rules:
1139+
1140+
* Replace dots (`.`) with underscores (`_`).
1141+
* Remove any dashes (`-`).
1142+
* Convert to uppercase.
1143+
1144+
For example, the configuration property `spring.main.log-startup-info` would be an environment variable named `SPRING_MAIN_LOGSTARTUPINFO`.
1145+
1146+
NOTE: Underscores cannot be used to replace the dashes in property names.
1147+
If you attempt to use `SPRING_MAIN_LOG_STARTUP_INFO` with the example above, no value will be bound.
1148+
1149+
Environment variables can also be used when binding to object lists.
1150+
To bind to a `List`, the element number should be surrounded with underscores in the variable name.
1151+
1152+
For example, the configuration property `my.acme[0].other` would use an environment variable named `MY_ACME_0_OTHER`.
1153+
1154+
1155+
11261156
[[boot-features-external-config-complex-type-merge]]
11271157
==== Merging Complex Types
11281158
When lists are configured in more than one place, overriding works by replacing the entire list.

0 commit comments

Comments
 (0)