Affects: Spring Boot 3.3.1

In case of spring.profiles.active java system properties ( -Dspring.profiles.active=...) take precedence over environment variables. If both are set, the profiles of Java System Properties win. This is contrary to the default source precedence documented in Externalized Configuration.

I encountered this, when I ran my spring boot application in IntelliJ using the mirrord plugin. This reads my environment from a kubernetes deployment and sets SPRING_PROFILES_ACTIVE=k8s . My intelliJ spring boot run profile was configured to use profiles dev,local, which sets the java system properties. I verified the expected properties with System.getenv() and System.property().

I verified that this was indeed a spring issue and not a weird behavior of the spring plugin.

As a workaround for my case, I've now configured my run profile to set the environment variable, which gets overridden by mirrord, but I assume this difference in precedence is not intended.

Comment From: simonbasle

The documentation you linked actually states the reverse: Java System Properties take precedence over OS environment variables as they come later in the list. This works as intended and documented.

Comment From: goatfryed-holos

Sorry, you are completely right. I was stupid.

Comment From: simonbasle

@goatfryed-holos nah, don't worry, happens to all of us 😉