java - 使用 REST 访问 JPA 数据失败 找不到合适的 HttpMessageConverter

标签 java spring rest jpa spring-boot

我已经为此苦苦挣扎了一段时间,但找不到解决方案。我正在运行 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/

相关文章:

java - JAX-RS (Jersey) ExceptionMapper - @Context 注入(inject)静态/单例类 - 它有效,但为什么呢?

java - WordNet 和 JWNL 是否能够将复数形式转换为单数形式以及将 ver(ing) 形式转换为名词形式?

java - 如何从以下cataLog中找到异常?

java - 不兼容的类型 : void cannot be converted to string

java - URL.openStream() 返回什么?

java - 从 Spring 托管 bean 向监听器发送事件

java - 使用Spring ReflectionUtils

rest - 有没有办法获取 YouTube 实时分析 API 数据?

Java Spring 表单标签问题

python - "Get"来自 cosmosdb 的 id 文档(不知道 _rid)