-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Spring Boot profiles and property resolution does not work as expected #11380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@pibakke I'm not sure I understand which part you think is a bug.
They aren't being ignored. In this example, the properties from
|
Hi Madhura I have read through the documentation found at Spring Boot features (chapter '25.1 Adding active profiles' in particular) and I still think there is a bug. You are right in that property-overrides done in Please not that Spring Boot detemines the same (correct) active profiles and profile ordering in both cases as evident in the log statement As you mention, the documentation states:
In my interpretation, I focus on the statement 'add rather than replace'. While the Spring Boot implementation seem to focus on the statement 'unconditionally'. In Spring Boot, profiles are used for activating profile specific beans (works as expected) and property resolution. My issue is with the property resolution part of Spring Boot. |
I believe the work we did in 2.0 for #8011 and #12159 has fixed this. Upgrading the POM I see this on the second run:
|
Hi Phil Thanks for looking into this issue. Unfortunately, the issue seems NOT to be fixed in Spring 2.0.0.RELEASE. I have verified this by following the steps in my initial post (un-commenting the first line in Building and executing the test with the command line This differs from the output you provided in your post. I would guess the reason is that you specified the
|
Re-opening so that we don't forget to double-check. |
Excellent ... please let me know if you need additional information. |
I believe I'm seeing the same behaviour as @pibakke on the second run:
|
Let's see if there's something more we can do that'll fix this in 2.0.x |
@pibakke, has this issue been solved for you? I'm experiencing it as well with 2.3.2.RELEASE... 😮 It turns out, this configuration injects
While this one injects
While the expected value in both cases is |
the problem still exists in id 'org.springframework.boot' version '2.4.1', but test ok in 2.1.7.RELEASE |
@boostmerlin Could you try 2.4.2 please? If your problem still occurs, please open a new issue and provide a minimal sample that reproduces the problem you're seeing. |
Environment:
From what I can understand, there seems to be a bug in how properties are resolved when
spring.profiles.include
is present in a property file. Ifspring.profiles.include
is present in a property file, property overrides done in profile-specific (application-<profile>.properties
) files are ignored.To re-produce the issue, please follow the steps below:
mvn clean install
Then, run the test using the command
mvn -Dspring.profiles.active=common,profile1 spring-boot:run
The test will output something similar to the below:
Now, un-comment the first line in the
application-profile1.properties
file (the one undersrc/main/resources
) and build the code again. Finally, re-run the test using the commandmvn -Dspring.profiles.active=profile1 spring-boot:run
The test will output something similar to the below:
As indicated above, both have the same profile ordering. Hence, I would assume they should both produce the same output. However, the values for Property4 and Property5 are only as expected in the first test run.
NB!
In the first test run, I explicitly specify 'common' and 'profile1' as active profiles on the command line. While in the second test run, only 'profile1' is set as active on the command line. However, now the 'common' profile is added (included) by un-commenting the line
spring.profiles.include=common
at the top of theapplication-profile1.properties
file.The text was updated successfully, but these errors were encountered: