diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/Profiles.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/Profiles.java index c0795ee879a0..138a7a9a7c48 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/Profiles.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/Profiles.java @@ -145,15 +145,16 @@ private List asReversedList(List list) { return reversed; } - private List asUniqueItemList(Collection strings) { - return asUniqueItemList(strings, null); + private List asUniqueItemList(Collection profiles) { + return asUniqueItemList(profiles, null); } - private List asUniqueItemList(Collection strings, Collection additional) { - LinkedHashSet uniqueItems = new LinkedHashSet<>(strings); + private List asUniqueItemList(Collection profiles, Collection additional) { + LinkedHashSet uniqueItems = new LinkedHashSet<>(); if (!CollectionUtils.isEmpty(additional)) { uniqueItems.addAll(additional); } + uniqueItems.addAll(profiles); return Collections.unmodifiableList(new ArrayList<>(uniqueItems)); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 9b4700409f6d..510830eeda25 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -594,15 +594,14 @@ void addProfiles() { } @Test - void addProfilesOrder() { + void additionalProfilesOrderedBeforeActiveProfiles() { SpringApplication application = new SpringApplication(ExampleConfig.class); application.setWebApplicationType(WebApplicationType.NONE); application.setAdditionalProfiles("foo"); ConfigurableEnvironment environment = new StandardEnvironment(); application.setEnvironment(environment); this.context = application.run("--spring.profiles.active=bar,spam"); - // Since Boot 2.4 additional should always be last - assertThat(environment.getActiveProfiles()).containsExactly("bar", "spam", "foo"); + assertThat(environment.getActiveProfiles()).containsExactly("foo", "bar", "spam"); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java index 9db066c8744e..677dc1329dd4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java @@ -308,7 +308,7 @@ void runWhenTwoProfilesSetProgrammaticallyLoadsWithPreservedProfileOrder() { void runWhenProfilesPresentBeforeConfigFileProcessingAugmentsProfileActivatedByConfigFile() { this.application.setAdditionalProfiles("other"); ConfigurableApplicationContext context = this.application.run("--spring.config.name=enableprofile"); - assertThat(context.getEnvironment().getActiveProfiles()).containsExactly("myprofile", "other"); + assertThat(context.getEnvironment().getActiveProfiles()).containsExactly("other", "myprofile"); String property = context.getEnvironment().getProperty("other.property"); assertThat(property).isEqualTo("fromotherpropertiesfile"); property = context.getEnvironment().getProperty("the.property"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ProfilesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ProfilesTests.java index 015aedd4c032..686ede607916 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ProfilesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ProfilesTests.java @@ -143,9 +143,9 @@ void getActiveWithProfileGroups() { @Test void getActiveWhenHasAdditionalIncludesAdditional() { MockEnvironment environment = new MockEnvironment(); - environment.setProperty("spring.profiles.active", "a,b,c"); + environment.setProperty("spring.profiles.active", "d,e,f"); Binder binder = Binder.get(environment); - Profiles profiles = new Profiles(environment, binder, Arrays.asList("d", "e", "f")); + Profiles profiles = new Profiles(environment, binder, Arrays.asList("a", "b", "c")); assertThat(profiles.getActive()).containsExactly("a", "b", "c", "d", "e", "f"); }