Skip to content

Commit

Permalink
doc(reference.pages.features.externalConfig): add notes about profile…
Browse files Browse the repository at this point in the history
…Specific
  • Loading branch information
alfredo-toledano committed Jul 4, 2024
1 parent f2b27d5 commit f586f50
Showing 1 changed file with 30 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,55 +236,46 @@
[[features.external-config.files.profile-specific]]
=== Profile Specific Files

* TODO:

As well as `application` property files, Spring Boot will also attempt to load profile-specific files using the naming convention `application-\{profile}`.
For example, if your application activates a profile named `prod` and uses YAML files, then both `application.yaml` and `application-prod.yaml` will be considered.

Profile-specific properties are loaded from the same locations as standard `application.properties`, with profile-specific files always overriding the non-specific ones.
If several profiles are specified, a last-wins strategy applies.
For example, if profiles `prod,live` are specified by the configprop:spring.profiles.active[] property, values in `application-prod.properties` can be overridden by those in `application-live.properties`.

[NOTE]
====
The last-wins strategy applies at the xref:features/external-config.adoc#features.external-config.files.location-groups[location group] level.
A configprop:spring.config.location[] of `classpath:/cfg/,classpath:/ext/` will not have the same override rules as `classpath:/cfg/;classpath:/ext/`.
For example, continuing our `prod,live` example above, we might have the following files:
----
/cfg
application-live.properties
/ext
application-live.properties
application-prod.properties
----
When we have a configprop:spring.config.location[] of `classpath:/cfg/,classpath:/ext/` we process all `/cfg` files before all `/ext` files:
. `/cfg/application-live.properties`
. `/ext/application-prod.properties`
. `/ext/application-live.properties`
* `spring.profiles.active=profile1,profile2,...`
** 👁️ if NO profiles are explicitly activated -> `application-default` is considered 👁️
*** := profile / contained by the `Environment`
* `application-\{profile}`
** naming convention
* if your application activates a profile (-- _Example:_ `prod` --) -> both are considered ( -- _Example:_ `application.yaml` and `application-prod.yaml` -- )
** 👁️BUT, profile-specific files always override the non-specific ones 👁️
** if several profiles are specified -> last-wins strategy (== last profile specific takes priority) | xref:features/external-config.adoc#features.external-config.files.location-groups[location group] level
*** `spring.config.location=classpath:/cfg/,classpath:/ext/` overriding rules != `spring.config.location=classpath:/cfg/;classpath:/ext/` overriding rules
* characteristics
** -- are loaded
*** from -- same locations as standard `application.properties`
*** 1! time
**** == if you have already directly xref:features/external-config.adoc#features.external-config.files.importing[imported] a profile specific property files -> NOT imported a 2 time
* _Example:_
** let's have `prod,live`, with the files

When we have `classpath:/cfg/;classpath:/ext/` instead (with a `;` delimiter) we process `/cfg` and `/ext` at the same level:
/cfg
application-live.properties
/ext
application-live.properties
application-prod.properties

. `/ext/application-prod.properties`
. `/cfg/application-live.properties`
. `/ext/application-live.properties`
====
*** if we have `spring.config.location=classpath:/cfg/,classpath:/ext/` -> we process all `/cfg` files before all `/ext` files:

The `Environment` has a set of default profiles (by default, `[default]`) that are used if no active profiles are set.
In other words, if no profiles are explicitly activated, then properties from `application-default` are considered.
. /cfg/application-live.properties
. /ext/application-prod.properties
. /ext/application-live.properties

NOTE: Properties files are only ever loaded once.
If you have already directly xref:features/external-config.adoc#features.external-config.files.importing[imported] a profile specific property files then it will not be imported a second time.
*** if we have `spring.config.location=classpath:/cfg/;classpath:/ext/` -> we process `/cfg` and `/ext` at the same level == in the order

. /ext/application-prod.properties
. /cfg/application-live.properties
. /ext/application-live.properties


[[features.external-config.files.importing]]
=== Importing Additional Data

* TODO:
Application properties may import further config data from other locations using the `spring.config.import` property.
Imports are processed as they are discovered, and are treated as additional documents inserted immediately below the one that declares the import.

Expand Down

0 comments on commit f586f50

Please sign in to comment.