Skip to content

Commit 1c2528d

Browse files
hoseaSchäfer, H.H. (Hans Hosea)
andauthored
1580: Fixes property substitution problem for active profiles (#1581)
* 1580: Fixes property substitution problem for active profiles Signed-off-by: Schäfer, H.H. (Hans Hosea) <[email protected]> * 1580: Test adjusted and extended for fixed behavior Signed-off-by: Schäfer, H.H. (Hans Hosea) <[email protected]> --------- Signed-off-by: Schäfer, H.H. (Hans Hosea) <[email protected]> Co-authored-by: Schäfer, H.H. (Hans Hosea) <[email protected]>
1 parent 06c4f64 commit 1c2528d

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/config/PropertySourceBootstrapConfiguration.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,9 @@ private String[] getProfilesForValue(Object property, ConfigurableEnvironment en
314314
}
315315

316316
private String[] resolvePlaceholdersInProfiles(String profiles, ConfigurableEnvironment environment) {
317-
return Arrays.stream(StringUtils.tokenizeToStringArray(profiles, ",")).map(s -> {
318-
if (s.startsWith("${") && s.endsWith("}")) {
319-
return environment.resolvePlaceholders(s);
320-
}
321-
else {
322-
return s;
323-
}
324-
}).toArray(String[]::new);
317+
return Arrays.stream(StringUtils.tokenizeToStringArray(profiles, ","))
318+
.map(environment::resolvePlaceholders)
319+
.toArray(String[]::new);
325320
}
326321

327322
/*

spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,15 @@ public void activeAndIncludeProfileFromBootstrapPropertySourceWithReplacementWit
666666
}
667667

668668
private void activeAndIncludeProfileFromBootstrapPropertySourceWithReplacement(String... properties) {
669-
PropertySourceConfiguration.MAP.put("spring.profiles.active", "${barreplacement},baz");
669+
PropertySourceConfiguration.MAP.put("spring.profiles.active", "before_${barreplacement}_after,baz");
670670
PropertySourceConfiguration.MAP.put("spring.profiles.include", "${barreplacement},baz,hello");
671671
context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
672672
.properties(properties)
673673
.profiles("foo")
674674
.sources(BareConfiguration.class)
675675
.run();
676-
then(context.getEnvironment().acceptsProfiles("baz", "bar", "hello", "foo")).isTrue();
677-
then(context.getEnvironment().getActiveProfiles()).contains("baz", "bar", "foo", "hello");
676+
then(context.getEnvironment().acceptsProfiles("baz", "bar", "hello", "foo", "before_bar_after")).isTrue();
677+
then(context.getEnvironment().getActiveProfiles()).contains("baz", "bar", "foo", "hello", "before_bar_after");
678678
}
679679

680680
@Test
@@ -739,6 +739,7 @@ void activeAndIncludeProfileFromBootstrapPropertySource_WhenMultiplePlacesHaveAc
739739
.anyMatch("local"::equals)).isTrue();
740740
}
741741

742+
742743
@Configuration(proxyBeanMethods = false)
743744
@EnableConfigurationProperties
744745
protected static class BareConfiguration {

0 commit comments

Comments
 (0)