Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring graceful shutdown - REQUEST METHOD POST NOT SUPPORTED

I'm trying to use the Spring endpoints to gracefully shut down my application but I'm getting an error:

2016-08-09 13:46:54.606  WARN 13315 --- [nio-8090-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Handler execution resulted in exception: Request method 'POST' not supported

I'm using this guide and I've set my application.properties to have endpoints.shutdown.enabled=true and also endpoints.shutdown.sensitive=false. I've also included compile("org.springframework.boot:spring-boot-starter-actuator") in my build.gradle.

When I send the CURL request: curl -X POST https://localhost:8090/shutdown -k
I get the following response from the server:

{"timestamp":1470747537792,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/shutdown"}

Am I doing anything incorrectly? Is there anything that I may be missing? I have CSRF enabled throughout the app so it's not an option to disable that for my application.

like image 273
px06 Avatar asked Jun 27 '26 16:06

px06


2 Answers

You need to send a CSRF token either as a header or a parameter or something. Your example:

curl -X POST https://localhost:8090/shutdown -k

does not include a CSRF token so of course Spring will reject it. That is indeed the whole point of the CSRF filter. You will need to decide whether it is appropriate to exclude the /shutdown uri from that filter or whether you want to require a token/nonce to be present.

like image 96
Dave L. Avatar answered Jun 29 '26 04:06

Dave L.


I'am using Springboot-1.5.3-RELEASE, use http method POST (not GET)。 It works.

like image 22
user3086002 Avatar answered Jun 29 '26 04:06

user3086002