Commit c7c8e032 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #5561 from eddumelendez/gh-5442

* pr/5561:
  Polish contribution
  Fix spring.profiles.active value handling
parents d27e2807 7cd31594
...@@ -95,6 +95,7 @@ import org.springframework.validation.BindException; ...@@ -95,6 +95,7 @@ import org.springframework.validation.BindException;
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Eddú Meléndez
*/ */
public class ConfigFileApplicationListener implements EnvironmentPostProcessor, public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
ApplicationListener<ApplicationEvent>, Ordered { ApplicationListener<ApplicationEvent>, Ordered {
...@@ -582,8 +583,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, ...@@ -582,8 +583,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
private Set<String> asResolvedSet(String value, String fallback) { private Set<String> asResolvedSet(String value, String fallback) {
List<String> list = Arrays List<String> list = Arrays
.asList(StringUtils.commaDelimitedListToStringArray(value != null .asList(StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(value != null
? this.environment.resolvePlaceholders(value) : fallback)); ? this.environment.resolvePlaceholders(value) : fallback)));
Collections.reverse(list); Collections.reverse(list);
return new LinkedHashSet<String>(list); return new LinkedHashSet<String>(list);
} }
......
...@@ -73,6 +73,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -73,6 +73,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Phillip Webb * @author Phillip Webb
* @author Dave Syer * @author Dave Syer
* @author Eddú Meléndez
*/ */
public class ConfigFileApplicationListenerTests { public class ConfigFileApplicationListenerTests {
...@@ -529,6 +530,20 @@ public class ConfigFileApplicationListenerTests { ...@@ -529,6 +530,20 @@ public class ConfigFileApplicationListenerTests {
"applicationConfig: [classpath:/testsetprofiles.yml]"); "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 @Test
public void yamlProfileCanBeChanged() throws Exception { public void yamlProfileCanBeChanged() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
......
---
spring:
profiles:
active: dev,healthcheck
\ No newline at end of file
---
spring:
profiles:
active: dev, healthcheck
\ No newline at end of file
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