diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java index a378d46b23..6aa3acf70b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ public class EnvironmentEndpointAutoConfiguration { @ConditionalOnMissingBean @ConditionalOnEnabledEndpoint @ConditionalOnBean(EnvironmentEndpoint.class) - public EnvironmentEndpointWebExtension environmentWebEndpointExtension( + public EnvironmentEndpointWebExtension environmentEndpointWebExtension( EnvironmentEndpoint environmentEndpoint) { return new EnvironmentEndpointWebExtension(environmentEndpoint); } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index 59c151c94c..8d69e01e74 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -21,11 +21,13 @@ import java.util.Map; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.core.env.Environment; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; @@ -49,6 +51,9 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @LocalManagementPort private int managementPort = 9011; + @Autowired + private Environment environment; + @Test public void testHome() { @SuppressWarnings("rawtypes") @@ -79,6 +84,17 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); } + @Test + public void testEnvNotFound() { + String unknownProperty = "test-does-not-exist"; + assertThat(this.environment.containsProperty(unknownProperty)).isFalse(); + ResponseEntity entity = new TestRestTemplate() + .withBasicAuth("user", getPassword()).getForEntity( + "http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + } + @Test public void testMissing() { ResponseEntity entity = new TestRestTemplate("user", getPassword())