Commit 87680b4e authored by Madhura Bhave's avatar Madhura Bhave

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
parent 62c93a4b
......@@ -370,8 +370,8 @@ public class ConfigFileApplicationListener
}
Binder binder = Binder.get(this.environment);
Set<Profile> 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;
}
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment