Skip to content

Commit 703b7d9

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents fedd7b9 + 67068fc commit 703b7d9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import org.springframework.core.env.ConfigurableEnvironment;
2323
import org.springframework.core.env.EnumerablePropertySource;
2424
import org.springframework.core.env.Environment;
25+
import org.springframework.core.env.PropertyResolver;
2526
import org.springframework.core.env.PropertySource;
2627
import org.springframework.core.env.PropertySources;
28+
import org.springframework.core.env.PropertySourcesPropertyResolver;
2729
import org.springframework.http.HttpStatus;
2830
import org.springframework.web.bind.annotation.PathVariable;
2931
import org.springframework.web.bind.annotation.ResponseBody;
@@ -93,7 +95,14 @@ private void getNames(PropertySources propertySources, NameCallback callback) {
9395

9496
@Override
9597
protected Object getOptionalValue(Environment source, String name) {
96-
Object result = source.getProperty(name);
98+
PropertyResolver resolver = source;
99+
if (source instanceof ConfigurableEnvironment) {
100+
resolver = new PropertySourcesPropertyResolver(
101+
((ConfigurableEnvironment) source).getPropertySources());
102+
((PropertySourcesPropertyResolver) resolver)
103+
.setIgnoreUnresolvableNestedPlaceholders(true);
104+
}
105+
Object result = resolver.getProperty(name);
97106
if (result != null) {
98107
result = ((EnvironmentEndpoint) getDelegate()).sanitize(name, result);
99108
}

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ public void regex() throws Exception {
138138
.andExpect(content().string(containsString("\"fool\":\"baz\"")));
139139
}
140140

141+
@Test
142+
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() throws Exception {
143+
Map<String, Object> map = new HashMap<String, Object>();
144+
map.put("my.foo", "${my.bar}");
145+
((ConfigurableEnvironment) this.context.getEnvironment()).getPropertySources()
146+
.addFirst(new MapPropertySource("unresolved-placeholder", map));
147+
this.mvc.perform(get("/env/my.*")).andExpect(status().isOk())
148+
.andExpect(content().string(containsString("\"my.foo\":\"${my.bar}\"")));
149+
}
150+
141151
@Configuration
142152
@Import({ JacksonAutoConfiguration.class,
143153
HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class,

0 commit comments

Comments
 (0)