Request to the endpoint fails with the following error:
400 Bad request org.springframework.http.converter.HttpMessageNotReadableException: Requir
@RequestBody
annotation binds the content sent in (POST / PUT) request body with the annotated variable. Since there is no 'body' part in GET request, spring throws HttpMessageNotReadableException to indicate the same.
As a general rule, you can only use @RequestBody
for the requests which can have 'body' content e.g. POST or PUT.
I met the similar problem today in spring-webmvc 5.1.5 and checked the library code. The HttpMessageNotReadableException
was thrown from RequestResponseBodyMethodProcessor.readWithMessageConverters
since it invoked readWithMessageConverters
and got null. There is an loop in readWithMessageConverters
searching suitable converter for the request Content-Type (for (HttpMessageConverter<?> converter : this.messageConverters)
), and because I didn't specify and Content-Type in request, it failed.
So I specified the header Content-Type: application/json
and solved the problem.