I have a spring boot application with context-path /services. The context-path entry in property file:
server.servlet.context-path=/services
When I use the URL http://localhost:8080/services/ with GET method, it is working fine and returning the static index.html file in response. But when I try to use the same URL http://localhost:8080/services/ with POST method, I am getting the following error:
{
"timestamp": "2020-11-11T07:06:37.341+00:00",
"status": 405,
"error": "Method Not Allowed",
"message": "",
"path": "/services/"
}
I have tried using redirect-context-root property, but that did not help. I also tried server.servlet.context-path=/services/ - but this also did not help. What property or configuration will force spring framework to allow POST method for any request with context-path with a trailing slash (/) ?
From the logs, I can see the view is getting resolved to [view="forward:index.html"], but right after that we see the ERROR HttpRequestMethodNotSupportedException: Request method 'POST' not supported. So not able to understand which spring class is responsible for throwing this error? And how can we suppress this behavior?
o.s.s.web.util.matcher.OrRequestMatcher : Trying to match using Ant [pattern='/rest/**']
o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/'; against '/rest/**'
o.s.s.web.util.matcher.OrRequestMatcher : No matches found
o.s.web.servlet.DispatcherServlet : POST "/services/", parameters={}
pertySourcedRequestMappingHandlerMapping : looking up handler for path: /
o.s.b.a.w.s.WelcomePageHandlerMapping : Mapped to ParameterizableViewController [view="forward:index.html"]
o.s.s.w.header.writers.HstsHeaderWriter : Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@363fa5d2
w.c.HttpSessionSecurityContextRepository : SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
.w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
o.s.web.servlet.DispatcherServlet : Completed 405 METHOD_NOT_ALLOWED
GetMapping? the fact that you get 405 and not 404 means that the path is good and you get to the controller, you just need to tell it there to handle POST - Nir Levy