diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 1e8e3facac..1fa3f64454 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -342,7 +342,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, } private Set initializeActiveProfiles() { - if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)) { + if (!this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY) + && !this.environment.containsProperty(INCLUDE_PROFILES_PROPERTY)) { return Collections.emptySet(); } // Any pre-existing active profiles set via property sources (e.g. System diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index e167841367..adb3a4a011 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -806,6 +806,15 @@ public class ConfigFileApplicationListenerTests { .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 public void activeProfilesCanBeConfiguredUsingPlaceholdersResolvedAgainstTheEnvironment() throws Exception {