Spring Download Return 405 instead of 404 for POST to an unknown URL

Disclaimer: I am new to Java, Spring and Spring Boot.

I would like Spring Boot to return 404 when trying to POST to a URL that does not exist. However, it is now returning 405 with an Allow header, which includes only GET and HEAD. Is there a way to configure which HTTP methods are allowed to get 404? I tried to implement a custom ErrorController, but this does not work.

To be clear : this is when I send POST to a URL that should not match any of my specific endpoints, for example http://example.com/some-bogus-thing

If you need more information for diagnosis, I would be happy to provide it. Given my unfamiliarity with the platform, I'm not sure what matters.

+6
source share
2 answers

HTTP 405 (Method not found) , when URL exists and you are trying to use an HTTP method that is not allowed for this URL.

if you call POST 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 find out all current mappings on this particular download instance, just go to the browser

 http://localhost:8080/mappings 
+1
source

Check here: https://github.com/spring-projects/spring-boot/issues/4876

The solution is this: spring: MVC: static-path-pattern: / static / **

0
source

Source: https://habr.com/ru/post/986749/


All Articles