Merge pull request #5561 from eddumelendez/gh-5442
* pr/5561: Polish contribution Fix spring.profiles.active value handling
This commit is contained in:
commit
c7c8e03270
|
|
@ -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<ApplicationEvent>, Ordered {
|
||||
|
|
@ -582,8 +583,8 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||
|
||||
private Set<String> asResolvedSet(String value, String fallback) {
|
||||
List<String> 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<String>(list);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
spring:
|
||||
profiles:
|
||||
active: dev,healthcheck
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
spring:
|
||||
profiles:
|
||||
active: dev, healthcheck
|
||||
Loading…
Reference in New Issue