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 93040195e5..49974ddfe6 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 @@ -95,6 +95,7 @@ import org.springframework.validation.BindException; * @author Phillip Webb * @author Stephane Nicoll * @author Andy Wilkinson + * @author Eddú Meléndez */ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, ApplicationListener, Ordered { @@ -582,8 +583,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, private Set asResolvedSet(String value, String fallback) { List list = Arrays - .asList(StringUtils.commaDelimitedListToStringArray(value != null - ? this.environment.resolvePlaceholders(value) : fallback)); + .asList(StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(value != null + ? this.environment.resolvePlaceholders(value) : fallback))); Collections.reverse(list); return new LinkedHashSet(list); } 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 bfbddf3161..8716c216f8 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 @@ -73,6 +73,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Phillip Webb * @author Dave Syer + * @author Eddú Meléndez */ public class ConfigFileApplicationListenerTests { @@ -529,6 +530,20 @@ public class ConfigFileApplicationListenerTests { "applicationConfig: [classpath:/testsetprofiles.yml]"); } + @Test + public void yamlSetsMultiProfiles() throws Exception { + this.initializer.setSearchNames("testsetmultiprofiles"); + this.initializer.postProcessEnvironment(this.environment, this.application); + assertThat(this.environment.getActiveProfiles()).containsExactly("dev", "healthcheck"); + } + + @Test + public void yamlSetsMultiProfilesWithWithespace() throws Exception { + this.initializer.setSearchNames("testsetmultiprofileswhitespace"); + this.initializer.postProcessEnvironment(this.environment, this.application); + assertThat(this.environment.getActiveProfiles()).containsExactly("dev", "healthcheck"); + } + @Test public void yamlProfileCanBeChanged() throws Exception { TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, diff --git a/spring-boot/src/test/resources/testsetmultiprofiles.yml b/spring-boot/src/test/resources/testsetmultiprofiles.yml new file mode 100644 index 0000000000..462f9d8785 --- /dev/null +++ b/spring-boot/src/test/resources/testsetmultiprofiles.yml @@ -0,0 +1,4 @@ +--- +spring: + profiles: + active: dev,healthcheck \ No newline at end of file diff --git a/spring-boot/src/test/resources/testsetmultiprofileswhitespace.yml b/spring-boot/src/test/resources/testsetmultiprofileswhitespace.yml new file mode 100644 index 0000000000..8b31dc528c --- /dev/null +++ b/spring-boot/src/test/resources/testsetmultiprofileswhitespace.yml @@ -0,0 +1,4 @@ +--- +spring: + profiles: + active: dev, healthcheck \ No newline at end of file