为什么我的应用程序中没有启用关闭(shutdown)端点?

huangapple go评论87阅读模式
英文:

Why is the shutdown endpoint not enabled in my application?

问题

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

我已经在我的pom.xml中添加了以下内容:

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

并在src/main/resources/application.yaml中添加了以下内容:

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

但是当我运行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中看不到关机端点:

为什么我的应用程序中没有启用关闭(shutdown)端点?

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

英文:

I am trying to add a shutdown endpoint actuator/shutdown in my Spring application as explained in this tutorial so that I can gracefully shutdown the application using a call like curl -X POST localhost:8080/actuator/shutdown.

I added

&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
&lt;/dependency&gt;

to my pom.xml and

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

to src/main/resources/application.yaml.

But when I run curl -X POST localhost:8080/actuator/shutdown, I get the following response:

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

I don't see the shutdown endpoint at http://localhost:8080/actuator:

为什么我的应用程序中没有启用关闭(shutdown)端点?

What am I doing wrong? What do I need to change in order for the actuator/shutdown endpoint to appear?

答案1

得分: 4

看起来你正在使用 YAML,`*` 在 YAML 中有特殊意义,必须用引号括起来。

下面的代码应该可以工作:

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


<details>
<summary>英文:</summary>

It appears you are using yaml, `*` has a special meaning in yaml and must be quoted.

The following should work

    management:
      endpoint:
        shutdown:
          enabled: true
      endpoints:
        web:
          exposure:
            include: &quot;*&quot;

</details>



# 答案2
**得分**: 3

可能是因为您使用的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


您可以在[发布说明][1]中了解有关Spring Boot 2.0变更的更多信息。

[1]: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Release-Notes

<details>
<summary>英文:</summary>

That may be, because of Spring/Actuator version, that you are using, Endpoints have changed quite a bit in Spring Boot 2.0 and, as a result, your configuration is out of date.
Try next:

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

OR

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

You can check more about changes in Spring Boot 2.0 in [release notes][1].


  [1]: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Release-Notes

</details>



huangapple
  • 本文由 发表于 2020年4月10日 19:10:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/61139071.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定