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 85c6bb7b93..46dec38815 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 @@ -393,8 +393,11 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, } // Any pre-existing active profiles set via property sources (e.g. System // properties) take precedence over those added in config files. - Set activeProfiles = bindSpringProfiles( - this.environment.getPropertySources()).getActiveProfiles(); + SpringProfiles springProfiles = bindSpringProfiles( + this.environment.getPropertySources()); + Set activeProfiles = new LinkedHashSet( + springProfiles.getActiveProfiles()); + activeProfiles.addAll(springProfiles.getIncludeProfiles()); maybeActivateProfiles(activeProfiles); return activeProfiles; } 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 4221a73229..3d67ce6934 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 @@ -837,6 +837,18 @@ public class ConfigFileApplicationListenerTests { assertThat(environment.acceptsProfiles("customdefault")).isTrue(); } + @Test + public void additionalProfilesCanBeIncludedFromAnyPropertySource() throws Exception { + SpringApplication application = new SpringApplication(Config.class); + application.setWebEnvironment(false); + this.context = application.run("--spring.profiles.active=myprofile", + "--spring.profiles.include=dev"); + String property = this.context.getEnvironment().getProperty("my.property"); + assertThat(property).isEqualTo("fromdevpropertiesfile"); + assertThat(this.context.getEnvironment().containsProperty("customdefault")) + .isFalse(); + } + private Condition matchingPropertySource( final String sourceName) { return new Condition(