Commit 7dd8e8c4 authored by Andy Wilkinson's avatar Andy Wilkinson

Honour spring.profiles.include even when .active has not been set

393cfe50 expanded the scope of spring.profiles.include so that it
could be used in any property source, and not just in a configuration
file. However, it did so in such a way that it would only take effect
when used outside of a configuration file if spring.profiles.active
was also set.

This commit updates ConfigFileApplicationListener so that included
profiles are activated when spring.profiles.active has not be set.

Closes gh-8244
parent 9a279335
...@@ -388,7 +388,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, ...@@ -388,7 +388,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
} }
private Set<Profile> initializeActiveProfiles() { private Set<Profile> initializeActiveProfiles() {
if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)) { if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)
&& !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) {
return Collections.emptySet(); return Collections.emptySet();
} }
// Any pre-existing active profiles set via property sources (e.g. System // Any pre-existing active profiles set via property sources (e.g. System
......
...@@ -851,6 +851,15 @@ public class ConfigFileApplicationListenerTests { ...@@ -851,6 +851,15 @@ public class ConfigFileApplicationListenerTests {
.isFalse(); .isFalse();
} }
@Test
public void profileCanBeIncludedWithoutAnyBeingActive() throws Exception {
SpringApplication application = new SpringApplication(Config.class);
application.setWebEnvironment(false);
this.context = application.run("--spring.profiles.include=dev");
String property = this.context.getEnvironment().getProperty("my.property");
assertThat(property).isEqualTo("fromdevpropertiesfile");
}
@Test @Test
public void activeProfilesCanBeConfiguredUsingPlaceholdersResolvedAgainstTheEnvironment() public void activeProfilesCanBeConfiguredUsingPlaceholdersResolvedAgainstTheEnvironment()
throws Exception { throws Exception {
......
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