【问题标题】:Why is the shutdown endpoint not enabled in my application?为什么我的应用程序中未启用关闭端点?
【发布时间】:2020-04-10 11:10:57
【问题描述】:

我正在尝试在我的 Spring 应用程序中添加一个关闭端点 actuator/shutdown,如 this tutorial 中所述,以便我可以使用类似 curl -X POST localhost:8080/actuator/shutdown 的调用优雅地关闭应用程序。

我加了

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

致我的pom.xml

management:
  endpoints.web.exposure.include: *
  endpoint.shutdown.enabled: true
endpoints.shutdown.enabled: true
management.endpoint.shutdown.enabled: true

src/main/resources/application.yaml

但是当我运行curl -X POST localhost:8080/actuator/shutdown 时,我得到以下响应:

{"timestamp":"2020-04-10T10:49:36.758+0000","status":404,"error":"Not Found",
"message":"No message available","path":"/actuator/shutdown"}

我在http://localhost:8080/actuator 没有看到关闭端点:

我做错了什么?为了使actuator/shutdown 端点出现,我需要进行哪些更改?

【问题讨论】:

  • 你在用yaml吗?

标签: java spring spring-boot-actuator


【解决方案1】:

看来你用的是yaml,*在yaml中有特殊含义,必须加引号。

以下应该可以工作

management:
  endpoint:
    shutdown:
      enabled: true
  endpoints:
    web:
      exposure:
        include: "*"

【讨论】:

    【解决方案2】:

    这可能是由于您使用的 Spring/Actuator 版本,端点在 Spring Boot 2.0 中发生了相当大的变化,因此您的配置已过时。 尝试下一个:

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

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

    您可以在release notes 中查看有关 Spring Boot 2.0 更改的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-11
      • 2019-04-13
      • 1970-01-01
      • 2018-01-13
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      相关资源
      最近更新 更多