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
This commit is contained in:
Madhura Bhave 2018-06-18 16:24:49 -07:00
parent 62c93a4b9a
commit 87680b4ee5
2 changed files with 13 additions and 1 deletions

View File

@ -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;
}

View File

@ -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,