-
Notifications
You must be signed in to change notification settings - Fork 41.2k
SpringApplication additional profiles and active profiles ordering changed with Spring Boot 2.4 #26189
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
@mzeijen You can fix this issue by using legacy processing @wilkinsona
Line 83 in 0c8f4e5
Lines 356 to 363 in 0c8f4e5
How would you think about this issue? |
@nguyensach From what I can see the ordering of the additional profiles and the active profiles happens in the SpringApplication, and I don't see that the legacy processing has any influence on it. In Spring Boot 2.3 it is done in the Lines 519 to 523 in 32e846d
In Spring Boot 2.4 it is done in the Lines 560 to 568 in 7caf238
The difference is that in Spring Boot 2.3 the list of profiles is created with |
@mzeijen I'm so sorry! According to the below test case, it seems this ordering change was an intentional one. Lines 594 to 604 in a654380
|
Although since Spring Boot 2.4 this ordering change was an intentional one, it needs to restore the old behavior when using legacy processing. If my PR #25817 is merged, it will restore the old behavior when using legacy processing as the bellow test case. |
@nguyensach |
Spring Boot version: 2.4
After upgrading to Spring Boot 2.4 from Spring Boot 2.3 I noticed that the ordering has changed of how
SpringApplication.additionalProfiles
are merged with theConfigurableEnvironment.getActiveProfiles()
.With Spring Boot 2.3 the ordering is: additional profiles, active profiles
With Spring Boot 2.4 the ordering is: active profiles, additional profiles
When running the test application below with Spring Boot
2.3
and Spring Boot2.4
you can see this easily in the logging:Spring Boot 2.3.10.RELEASE profiles ordering: additional, active
Spring Boot 2.4.5 profiles ordering: active, additional
This ordering change also affects the
@ActiveProfiles
test annotation. The profiles activated via the annotation now also have a lesser priority then the additional profiles (if you are wondering how we are setting additional profiles in combination with running tests, this is because we are actually using aApplicationStartingEvent
ApplicationListener
, registered via thespring.factories
to call theSpringApplication.setAdditionalProfiles()
with an environment specific profile).This change has the effect that our
application-{profile}.yml
property sources are now getting different precedence, which caused issues for us when running tests, because property values where not being overridden in the expected order anymore.I wonder if this change in ordering was an intentional one or that it is a mistake. I couldn't find any remarks regarding the change in the changelog. I have also read the https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-Config-Data-Migration-Guide but I couldn't distill this information from that document as well. If the ordering change is intentional then I recommend adding a note in the migration guide.
Test code:
The text was updated successfully, but these errors were encountered: