diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ShutdownEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ShutdownEndpoint.java index 38553b9f3b..d74075da2b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ShutdownEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ShutdownEndpoint.java @@ -20,8 +20,6 @@ import java.util.Collections; import java.util.Map; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.properties.ManagementServerProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -40,8 +38,7 @@ public class ShutdownEndpoint extends AbstractEndpoint> impl private ConfigurableApplicationContext context; - @Autowired(required = false) - private ManagementServerProperties configuration = new ManagementServerProperties(); + private boolean enabled = false; /** * Create a new {@link ShutdownEndpoint} instance. @@ -52,12 +49,17 @@ public class ShutdownEndpoint extends AbstractEndpoint> impl @Override public Map invoke() { - if (this.configuration == null || !this.configuration.isAllowShutdown() - || this.context == null) { + + if (!this.enabled) { return Collections. singletonMap("message", "Shutdown not enabled, sorry."); } + if (this.context == null) { + return Collections. singletonMap("message", + "No context to shutdown."); + } + new Thread(new Runnable() { @Override public void run() { @@ -87,4 +89,11 @@ public class ShutdownEndpoint extends AbstractEndpoint> impl return POST_HTTP_METHOD; } + public boolean isEnabled() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/ManagementServerProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/ManagementServerProperties.java index df0f847801..352245fb87 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/ManagementServerProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/properties/ManagementServerProperties.java @@ -42,18 +42,8 @@ public class ManagementServerProperties implements SecurityPrequisite { @NotNull private String contextPath = ""; - private boolean allowShutdown = false; - private Security security = maybeCreateSecurity(); - public boolean isAllowShutdown() { - return this.allowShutdown; - } - - public void setAllowShutdown(boolean allowShutdown) { - this.allowShutdown = allowShutdown; - } - /** * Returns the management port or {@code null} if the * {@link ServerProperties#getPort() server port} should be used. diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java index 920583b042..49bca4fcc0 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ShutdownEndpointTests.java @@ -17,8 +17,6 @@ package org.springframework.boot.actuate.endpoint; import org.junit.Test; -import org.springframework.boot.actuate.endpoint.ShutdownEndpoint; -import org.springframework.boot.actuate.properties.ManagementServerProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -32,6 +30,7 @@ import static org.junit.Assert.assertTrue; * Tests for {@link ShutdownEndpoint}. * * @author Phillip Webb + * @author Dave Syer */ public class ShutdownEndpointTests extends AbstractEndpointTests { @@ -53,16 +52,11 @@ public class ShutdownEndpointTests extends AbstractEndpointTests