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 e76ba1d79e..f67ebf2884 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 @@ -553,7 +553,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, private void addProfiles(Set profiles) { for (Profile profile : profiles) { this.profiles.add(profile); - if (!this.environment.acceptsProfiles(profile.getName())) { + if (!environmentHasActiveProfile(profile.getName())) { // If it's already accepted we assume the order was set // intentionally prependProfile(this.environment, profile); @@ -561,6 +561,15 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, } } + private boolean environmentHasActiveProfile(String profile) { + for (String activeProfile : this.environment.getActiveProfiles()) { + if (activeProfile.equals(profile)) { + return true; + } + } + return false; + } + private void prependProfile(ConfigurableEnvironment environment, Profile profile) { Set profiles = new LinkedHashSet(); 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 6dd9aee673..c0f9ce43d0 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 @@ -824,7 +824,9 @@ public class ConfigFileApplicationListenerTests { ConfigurableEnvironment environment = this.context.getEnvironment(); assertThat(environment.containsProperty("customprofile")).isTrue(); assertThat(environment.containsProperty("customprofile-specific")).isTrue(); - assertThat(environment.containsProperty("customprofile-customdefault")).isFalse(); + assertThat(environment.containsProperty("customprofile-customdefault")).isTrue(); + assertThat(this.context.getEnvironment().acceptsProfiles("customdefault")) + .isTrue(); } private Condition matchingPropertySource( diff --git a/spring-boot/src/test/resources/customprofile-customdefault.properties b/spring-boot/src/test/resources/customprofile-customdefault.properties index 0888bcc459..4770be45e4 100644 --- a/spring-boot/src/test/resources/customprofile-customdefault.properties +++ b/spring-boot/src/test/resources/customprofile-customdefault.properties @@ -1 +1,2 @@ +spring.profiles.include=specific customprofile-customdefault=true diff --git a/spring-boot/src/test/resources/customprofile.properties b/spring-boot/src/test/resources/customprofile.properties index e82886ef73..4e26520999 100644 --- a/spring-boot/src/test/resources/customprofile.properties +++ b/spring-boot/src/test/resources/customprofile.properties @@ -1,2 +1,2 @@ -spring.profiles.active=specific +spring.profiles.active=customdefault customprofile=true