From 3720fb0e69db1c935e3e33e6a2dfbe4837593fd8 Mon Sep 17 00:00:00 2001 From: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:17:15 -0500 Subject: [PATCH] Porting documentation --- .../configmap-propertysource.adoc | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/modules/ROOT/pages/property-source-config/configmap-propertysource.adoc b/docs/modules/ROOT/pages/property-source-config/configmap-propertysource.adoc index 3c637c3f..64727ccd 100644 --- a/docs/modules/ROOT/pages/property-source-config/configmap-propertysource.adoc +++ b/docs/modules/ROOT/pages/property-source-config/configmap-propertysource.adoc @@ -83,6 +83,34 @@ This is what we will end-up loading: - `not-my-app.yaml` _ignored_, since it does not match `spring.application.name` - `someProp: someValue` plain property +The order of loading properties is a as follows: + +- first load all properties from `my-app.yaml` +- then all from profile-based sources: `my-app-k8s.yaml` +- then all plain properties `someProp: someValue` + +This means that profile based sources take precedence over non-profile based sources (just like in a vanilla Spring app); and plain properties take precedence over both profile and non-profile based sources. Here is an example: + +==== +[source] +---- +kind: ConfigMap +apiVersion: v1 +metadata: + name: my-app +data: + my-app-k8s.yaml: |- + key1=valueA + key2=valueB + my-app.yaml: |- + key1=valueC + key2=valueA + key1: valueD +---- +==== + +After processing such a ConfigMap, this is what you will get in the properties: `key1=valueD`, `key2=valueB`. + The single exception to the aforementioned flow is when the `ConfigMap` contains a *single* key that indicates the file is a YAML or properties file. In that case, the name of the key does NOT have to be `application.yaml` or `application.properties` (it can be anything) and the value of the property is treated correctly.