use*_*969 5 spring spring-boot
当我发出以下命令时:
curl localhost:8080/actuator/env -d'{"name":"test",value:"hello world!"}' -H "Content-type: application/json"
Run Code Online (Sandbox Code Playgroud)
我得到:
{"timestamp":"2020-03-09T16:21:18.245+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","path":"/actuator/env
Run Code Online (Sandbox Code Playgroud)
我的 application.yml 文件公开了端点,我可以毫无问题地发出 GET 请求:
management:
endpoints:
web:
exposure:
include: "*"
Run Code Online (Sandbox Code Playgroud)
我没有启用Spring Security。如何向 Spring Actuator 端点提交 POST 请求?我正在使用 Spring Boot 2.2.5。
在 Spring Boot 的当前版本(2.2.5+)中,如果您想在应用程序运行时更新/设置环境属性,那么暴露 env 端点是不够的。
你必须设置
management.endpoint.env.post.enabled=true
Run Code Online (Sandbox Code Playgroud)
之后,您可以使用以下命令更新属性:
curl -H "Content-Type: application/json" -X POST -d '{"name":"foo", "value":"bar"}' http://localhost:8080/my-application/actuator/env
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4013 次 |
最近记录: |