Disclaimer: I'm new to Java, Spring, and Spring Boot.
I'd like to have Spring Boot return a 404 when trying to POST to a URL that doesn't exist. However, right now it's returning a 405, with an Allow header that only includes GET and HEAD. Is there a way to customize which HTTP methods are allowed so that I get a 404? I've tried implementing a custom ErrorController, but that doesn't seem to work.
To be clear: this is when I'm POSTing to a URL that shouldn't be matched by any of my defined endpoints, e.g http://example.com/some-bogus-thing
If any more information is needed to diagnose this, I'd be happy to provide it. Given my unfamiliarity with the platform, I'm not sure what's relevant.
HTTP 405 (Method not found)
is returned, when URL exists
and you try to use an HTTP Method that is not allowed on that particular URL mapping.
if you invoke a POST on below .../test
then it will return HTTP 405 and vice versa.
@RequestMapping(value = "/test", method = RequestMethod.GET)
if there is no URL mapping for any of the HTTP methods, then it will return HTTP 404.
To know all the current mappings on that particular boot instance, just to go browser
http://localhost:8080/mappings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With