Skip to content

Commit 8c6c4fa

Browse files
committed
Overhaul "externalized configuration" docs
Update the "externalized configuration" reference documentation following the recent updates. Closes gh-22521
1 parent 3352024 commit 8c6c4fa

File tree

3 files changed

+279
-253
lines changed

3 files changed

+279
-253
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -351,39 +351,29 @@ See "`<<spring-boot-features.adoc#boot-features-profiles>>`" in the "`Spring Boo
351351

352352
[[howto-change-configuration-depending-on-the-environment]]
353353
=== Change Configuration Depending on the Environment
354-
A YAML file is actually a sequence of documents separated by `---` lines, and each document is parsed separately to a flattened map.
354+
Spring Boot supports multi-document YAML and Properties files (see <<spring-boot-features#boot-features-external-config-files-multi-document>> for details) which can be activated conditionally based on the active profiles.
355355

356-
If a YAML document contains a `spring.profiles` key, then the profiles value (a comma-separated list of profiles) is fed into the Spring `Environment.acceptsProfiles()` method.
357-
If any of those profiles is active, that document is included in the final merge (otherwise, it is not), as shown in the following example:
356+
If a document contains a `spring.config.activate.on-profile` key, then the profiles value (a comma-separated list of profiles or a profile expression) is fed into the Spring `Environment.acceptsProfiles()` method.
357+
If the profile expression matches then that document is included in the final merge (otherwise, it is not), as shown in the following example:
358358

359359
[source,yaml,indent=0,subs="verbatim,quotes,attributes"]
360360
----
361-
server:
362-
port: 9000
361+
server.port: 9000
363362
---
364-
365-
spring:
366-
profiles: development
367-
server:
368-
port: 9001
369-
363+
spring.config.activate.on-profile: development
364+
server.port: 9001
370365
---
371-
372-
spring:
373-
profiles: production
374-
server:
375-
port: 0
366+
spring.config.activate.on-profile: production
367+
server.port: 0
376368
----
377369

378370
In the preceding example, the default port is 9000.
379371
However, if the Spring profile called '`development`' is active, then the port is 9001.
380372
If '`production`' is active, then the port is 0.
381373

382-
NOTE: The YAML documents are merged in the order in which they are encountered.
374+
NOTE: The documents are merged in the order in which they are encountered.
383375
Later values override earlier values.
384376

385-
To do the same thing with properties files, you can use `application-$\{profile}.properties` to specify profile-specific values.
386-
387377

388378

389379
[[howto-discover-build-in-options-for-external-properties]]

0 commit comments

Comments
 (0)