From 87680b4ee595ef9417495f443f0b475ff96e9e87 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Mon, 18 Jun 2018 16:24:49 -0700 Subject: [PATCH] Fix profile precedence when active and include provided Before 2.0.2, if profiles were activated via the environment using the active and include profile property, profiles specified via the active property would take precedence. This commit restores that behavior. Fixes gh-13513 --- .../config/ConfigFileApplicationListener.java | 2 +- .../config/ConfigFileApplicationListenerTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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 62a61f77d45..94abc4491f3 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 @@ -370,8 +370,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 1d82d42e113..34428de8bfd 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 @@ -400,6 +400,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,