英文:
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
中看不到关机端点:
我做错了什么?为了使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
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
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:
{"timestamp":"2020-04-10T10:49:36.758+0000","status":404,"error":"Not Found",
"message":"No message available","path":"/actuator/shutdown"}
I don't see the shutdown endpoint at http://localhost:8080/actuator
:
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: "*"
</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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论