While loading of YAML files in home directory was fixed in #19081 it appears it is ignoring the profiles defined by the spring.profiles property and loading in all YAML documents (the sections in a YAML file) as property sources.

When running the example application with the example spring-boot-devtools.yaml with no profiles activate I would expect only one YAML document to be loaded, the top one which should be "default" property scope.

Example Project: devtools-profile-loading.zip I have added log statements to enumerate the loading property sources and just by starting up the example project you can see that all documents in spring-boot-devtools.yaml are loaded.

./mvn spring-boot-run

Example ~/.config/spring-boot/spring-boot-devtools.yaml: spring-boot-devtools.yaml.txt


default.profile.property: "Default Profile Property"

---

spring:
  profiles: p1

p1.profile.property: "from p1"

---

spring:
  profiles: p2

p2.profile.property: "from p2"

---

spring:
  profiles: p3

p2.profile.property: "from p3"
---

spring:
  profiles: p1 & p2

p1-p2.profile.property: "from p1 & p2"

---

spring:
  profiles: p2 & p3

p2-p3.profile.property: "from p2 & p3"

---

spring:
  profiles: p1 & p3

p1-p3.profile.property: "from p1 & p3"

---

spring:
  profiles:
    - p1
    - p2
    - p3

p1-or-p2-or-p3.profile.property: "from p1 | p2 | p3"

Comment From: mbhave

You're right @ddcruver. I don't think the DevtoolsEnvironmentPostProcessor takes active profiles into account when loading the spring-boot-devtools.yaml. I don't think we should support this since there's no equivalent way to this with spring-boot-devtools.properties unless we added support for -{profile}.properties. Spring Boot originally supported only the .properties format for DevTools and .yml was added as a convenience. Let's see what the rest of the team thinks.

Comment From: ddcruver

The fact that spring-boot-devtools.properties does not support multiple profiles is why I wanted to use the spring-boot-devtools.yaml variation.

I would argue the fact that DevTool YAML files work differently than YAML configuration files in other places causes more inconsistency.

Also spring-boot-devtools.properties have their own configuration directory ~/.config/spring-boot/ now support for multiple files can be done without adding to a users home directory files.

Some people prefer one or the other format so seeing continued support for both would be good and since these files are local to a developer they have more freedom to use whichever they want in their development environment.

Comment From: wilkinsona

I agree with Madhura that we should not support this.

The documentation already contains a note about profiles:

Profiles activated in the above files will not affect the loading of profile-specific configuration files.

We should expand upon this to note that profile-specific configuration is not supported in general. That feels consistent to me as this isn’t an application.(properties|yaml) file.

Also spring-boot-devtools.properties have their own configuration directory ~/.config/spring-boot/ now support for multiple files can be done without adding to a users home directory files.

We’ve discussed this before: https://github.com/spring-projects/spring-boot/issues/16042#issuecomment-482205443. We prefer to align with that standard and use a consistent location across platforms.

Comment From: ddcruver

@wilkinsona I think there is a little miss understanding here.

We’ve discussed this before: #16042 (comment). We prefer to align with that standard and use a consistent location across platforms.

I do agree with it being in ~/.config/spring-boot/ it is cross-platform friendly the reason why I mentioned it was because of the potential of adding -{profile}.properties support to the DevTools home.

The documentation already contains a note about profiles:

Profiles activated in the above files will not affect the loading of profile-specific configuration files.

I am not asking for devtools configuration files to activate any profiles, just that profiles contained in them should be filtered like any other YAML file. I understand that activating profiles would cause confusion and adds lots of complexity to the code. I have been debugging the property loading lately and understand a lot is going on.

Right now you can add an arbitrary YAML file on your spring.config.location and it will support filtering of inactive profile YAML documents. To be clear I am only talking about Multi-profile YAML Documents. Not anything like spring-devtools-{profile}.yaml, ex.). spring-devtools-production.yaml

Also I am not imply that -{profile}.properties be supported in any file that is configured, just the "main" configuration file and the devtool one. But back on that note, if we drop the whole notion of adding support for -{profile}.properties in devtools I wouldn't be effected by that.

I just saw it as a value add for those that don't like YAML and partly because mbhave said this:

I don't think we should support this since there's no equivalent way to this with spring-boot-devtools.properties unless we added support for -{profile}.properties

Comment From: ddcruver

We have been focusing on what it was doing and what it should be doing but I haven't even expressed my use case:

I would like to have DevTools contain multiple configuration for different environments and allow me to pass the profiles to my Microservices in order to activate one or more but not all of the profiles in my ~/.config/spring-boot/spring-boot-devtools.yaml configuration.

This could be emulated by commenting out lines or swapping in different spring-boot-devtools.yaml files but this would cause friction in my workflow.

Comment From: wilkinsona

The ~/.config/spring-boot/spring-boot-devtools.(properties|yaml) file is primarily intended for configuring global DevTools settings. You've gone quite a bit beyond that into an area that we do not want to support. If you want profile-specific configuration, you should use application.(properties|yaml) files as that's where profile-specific configuration is provided. You can add additional locations use spring.config.additional-location.

We'll expand the existing note in the documentation to clarify when profile-specific configuration is and is not available.

Comment From: ddcruver

I think it would be a good idea to log a warning if any spring.profiles are found in DevTools YAML files.