Spring @GetMapping with @RequestParam and @RequestBody fails with HttpMessageNotReadableException

后端 未结 2 1044
醉酒成梦
醉酒成梦 2020-12-11 19:43

Request to the endpoint fails with the following error:

400 Bad request org.springframework.http.converter.HttpMessageNotReadableException: Requir

2条回答
  •  被撕碎了的回忆
    2020-12-11 20:48

    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.

提交回复
热议问题