Annotation @ActiveProfiles doesn't preserve the order of defined profiles in tests in spring boot 2.3.5.RELEASE I have defined two profiles (europe and belgium) and marked test class with @ActiveProfiles({"europe", "belgium"}) Profiles have been loaded in alphabetical order instead of defined in the annotation.

I wrote test for that case. It fails due to unexpected behavior ffffffff

Log from context startup during test execution 2020-10-31 02:00:03.091 INFO 15818 --- [ main] c.e.d.DemoProfilesApplicationTests : The following profiles are active: belgium,europe

In spring boot 2.3.4.RELEASE same test pass

Comment From: wilkinsona

Thanks for the report. This is caused by a regression in Spring Framework due to the changes for https://github.com/spring-projects/spring-framework/issues/25973. We'll transfer this issue to the Framework project so that they can take a look.

@sbrannen The ordering of profiles is important and I think it should be preserved. For example, in Spring Boot the ordering of the profiles determines which profile-specific configuration file takes precedence. IMO, it's correct that a cache miss should occur when the same profiles are activated but in a different order.

Comment From: sbrannen

@tbalachowski, thanks for raising the issue.


@wilkinsona, since Spring Boot relies on the registration order, we agree that it is a regression and are reverting the corresponding changes made to 5.3.x, 5.2.x, and 5.1.x.

We would also be grateful if tests could be added to the Spring Boot Test test suite to catch related regressions in the future (and to verify that this has been fixed for Boot).

Comment From: wilkinsona

Thanks, Sam. We have numerous tests that verify that changing profile ordering affects property resolution, but hadn't anticipated Framework changing the ordering and doing so only in tests. It feels a little odd to be adding something to Boot to verify Framework's behaviour, but we can certainly do so if you don't feel that Framework's own test suite is sufficient to avoid the problem being reintroduced.

Comment From: sbrannen

Hi @wilkinsona,

It feels a little odd to be adding something to Boot to verify Framework's behaviour, but we can certainly do so if you don't feel that Framework's own test suite is sufficient to avoid the problem being reintroduced.

We think it makes sense for Boot to have tests in place for behavior that is specific to Boot, and this applies to the registration order of active bean definition profiles, since the order does not matter in Spring Framework but does matter in Spring Boot.