How to POST to Spring Boot Actuator?

Viewed 2006

When I issue the following:

curl localhost:8080/actuator/env -d'{"name":"test",value:"hello world!"}' -H "Content-type: application/json"

I get:

{"timestamp":"2020-03-09T16:21:18.245+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","path":"/actuator/env

My application.yml file exposes the endpoint and I can issue a GET request without any issue:

management:
    endpoints:
        web:
            exposure:
                include: "*"

I do not have Spring Security enabled. How can I enable submission of POST requests to Spring Actuator endpoints? I'm using Spring Boot 2.2.5.

1 Answers

In the current versions(2.2.5+) of spring boot exposing the env endpoint is not enough if you want to update/set the environment property while the application is running.

You have to set

management.endpoint.env.post.enabled=true

After this you can update the property by using the below command:

curl -H "Content-Type: application/json" -X POST -d '{"name":"foo", "value":"bar"}' http://localhost:8080/my-application/actuator/env
Related