我已经为此苦苦挣扎了一段时间,但找不到解决方案。我正在运行 SpringBoot 指南,使用 REST 访问 JPA 数据 (http://spring.io/guides/gs/accessing-data-rest/) 不工作。
只要下载并运行它就可以正常运行,允许 GET 调用
http://localhost:8080/people
使用 postman 。但是,每当我尝试 PUT 或 POST 时,我都会收到以下错误
{
"cause": null,
"message": "No suitable HttpMessageConverter found to read request body into object of type class hello.Person from request with content type of text/plain;charset=UTF-8!"
}
我通过 PUT 传递的 json 是
{
"firstName": "Dave",
"lastName": "Something"
}
这只是运行原始项目,没有任何更改。许多其他指南项目工作正常,所以我知道 MVN、Spring boot 等工作正常。
尝试了很多论坛,但没有任何建议有效。
如有任何帮助,我们将不胜感激。
谢谢 戴夫
最佳答案
您的 POST 请求的内容类型为 text/plain
,服务器不知道如何将纯文本转换为 hello.Person
实例。
您需要通过将请求的 Content-Type
header 设置为 application/json
来告诉服务器您正在发送 JSON
关于java - 使用 REST 访问 JPA 数据失败 找不到合适的 HttpMessageConverter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27115334/