diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java index 2b835613e4..cbb937dd15 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpoint.java @@ -69,7 +69,8 @@ public class EnvironmentEndpoint extends AbstractEndpoint> { EnumerablePropertySource enumerable = (EnumerablePropertySource) source; Map properties = new LinkedHashMap(); for (String name : enumerable.getPropertyNames()) { - properties.put(name, sanitize(name, resolver.getProperty(name))); + Object resolved = resolver.getProperty(name, Object.class); + properties.put(name, sanitize(name, resolved)); } properties = postProcessSourceProperties(sourceName, properties); if (properties != null) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java index 5ac94c7196..1f101b38ec 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java @@ -93,7 +93,7 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter @Override protected Object getOptionalValue(Environment source, String name) { - Object result = ((EnvironmentEndpoint) getDelegate()).getResolver().getProperty(name); + Object result = ((EnvironmentEndpoint) getDelegate()).getResolver().getProperty(name, Object.class); if (result != null) { result = ((EnvironmentEndpoint) getDelegate()).sanitize(name, result); } @@ -102,7 +102,7 @@ public class EnvironmentMvcEndpoint extends EndpointMvcAdapter @Override protected Object getValue(Environment source, String name) { - String result = source.getProperty(name); + Object result = source.getProperty(name, Object.class); if (result == null) { throw new NoSuchPropertyException("No such property: " + name); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java index 3673de9acc..363ed2551e 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.endpoint; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import org.junit.After; @@ -29,6 +30,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; import static org.assertj.core.api.Assertions.assertThat; @@ -255,6 +257,24 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests source = new HashMap(); + source.put("foo", Collections.singletonMap("bar", "baz")); + propertySources.addFirst(new MapPropertySource("test", source)); + this.context.register(Config.class); + this.context.refresh(); + EnvironmentEndpoint report = getEndpointBean(); + Map env = report.invoke(); + Map testProperties = (Map) env + .get("test"); + Map foo = (Map) testProperties.get("foo"); + assertThat(foo.get("bar")).isEqualTo("baz"); + } + @Configuration @EnableConfigurationProperties public static class Config { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java index cb7816b5ec..9cfd7e8895 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpointTests.java @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.endpoint.mvc; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -39,6 +40,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; @@ -160,6 +162,18 @@ public class EnvironmentMvcEndpointTests { .andExpect(content().string(containsString("\"my.foo\":\"******\""))); } + @SuppressWarnings("unchecked") + @Test + public void propertyWithTypeOtherThanStringShouldNotFail() throws Exception { + ConfigurableEnvironment environment = (ConfigurableEnvironment) this.context.getEnvironment(); + MutablePropertySources propertySources = environment.getPropertySources(); + Map source = new HashMap(); + source.put("foo", Collections.singletonMap("bar", "baz")); + propertySources.addFirst(new MapPropertySource("test", source)); + this.mvc.perform(get("/env/foo.*")).andExpect(status().isOk()) + .andExpect(content().string("{\"foo\":{\"bar\":\"baz\"}}")); + } + @Configuration @Import({ JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class,