diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index b4e95385ce6..e699e54ddd6 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -371,8 +371,8 @@ public class ConfigFileApplicationListener } Binder binder = Binder.get(this.environment); Set activeProfiles = new LinkedHashSet<>(); - activeProfiles.addAll(getProfiles(binder, ACTIVE_PROFILES_PROPERTY)); activeProfiles.addAll(getProfiles(binder, INCLUDE_PROFILES_PROPERTY)); + activeProfiles.addAll(getProfiles(binder, ACTIVE_PROFILES_PROPERTY)); return activeProfiles; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 48b80669a57..6799bc51da3 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -401,6 +401,18 @@ public class ConfigFileApplicationListenerTests { validateProfilePrecedence(null, "dev", "other"); } + @Test + public void profilesAddedToEnvironmentViaActiveAndIncludeProperty() { + // Active profile property takes precedence + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, + "spring.profiles.active=dev", "spring.profiles.include=other"); + this.initializer.postProcessEnvironment(this.environment, this.application); + assertThat(this.environment.getActiveProfiles()).contains("dev", "other"); + assertThat(this.environment.getProperty("my.property")) + .isEqualTo("fromdevpropertiesfile"); + validateProfilePrecedence(null, "other", "dev"); + } + @Test public void profilesAddedToEnvironmentAndViaPropertyDuplicate() { TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,