Spring Boot v2.0.0.M7 Actuator 的关机功能如何设置?

How to make Spring Boot v2.0.0.M7 Actuator's shutdown work?

我创建了 hello world Spring Boot v2.0.0.M7 应用程序,添加了执行器,启用了关机功能,但它无法正常工作。

application.properties

server.port=8082
endpoint.shutdown.enabled=true
endpoint.shutdown.sensitive=false

身体健康

但不是关机

我做错了什么?

在 Spring Boot 2.0 中端点发生了很大变化,因此您的配置已过时。您需要启用端点并通过 HTTP 公开它:

management.endpoints.web.expose=*
management.endpoint.shutdown.enabled=true

如评论中所述和 Actuator HTTP API documentation 中所述,您还需要发出 POST 请求,以便无法在浏览器中访问端点。您可以在命令行中使用类似 curl 的内容:

$ curl -X POST localhost:8080/actuator/shutdown

您可以通过阅读 release notes 了解更多关于 Spring Boot 2.0 的变化。

spring-boot 2.0 默认
management.endpoints.web.exposure.include=info, health,
更改为
management.endpoints.web.exposure.include=info, health, shutdown

spring 引导版本:2.0.1.RELEASE

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

application.properties

management.endpoints.web.exposure.include=shutdown
management.endpoint.shutdown.enabled=true

然后,尝试

$ curl -X POST localhost:8080/actuator/shutdown