rest - NoMessageBodyWriterFoundFailure

标签 rest maven jboss jax-rs resteasy

我收到以下错误.. org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:无法找到类型为“服务类”、媒体类型为 application/json 的响应对象的 MessageBodyWriter。

但是我已经包含了

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxb-provider</artifactId>
    <version>3.0.8.Final</version>
</dependency>

我已经读到我可以添加 @XmlRootElement ,但我认为如果 POM 中包含上述依赖项,它应该可以工作?

最佳答案

来自documentation :

A JAXB Provider is selected by RESTEasy when a parameter or return type is an object that is annotated with JAXB annotations (such as @XmlRootEntity or @XmlType) or if the type is a JAXBElement.

因此,您要么添加提到的注释,要么选择不需要 JAXB 注释的 JSON 序列化器,例如 jackson .然后您应该添加以下依赖项:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson-provider</artifactId>
    <version>3.0.8.Final</version>
</dependency>

关于rest - NoMessageBodyWriterFoundFailure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25542082/

相关文章:

java - 更新 Docker 中的自定义配置文件

java - 覆盖 wildfly/jboss 模块中特定 java 类文件的类加载

java - 使用 Jersey 获取 REST 资源作为 List<T>

rest - 使用 or 条件定义查询参数的 RESTful 最佳实践是什么?

java - Sonar 项目属性排除规则鱿鱼 :S1191

git - git 子模块的 build.gradle 更改

maven - Maven Polyglot 怎么了?

tomcat - 从 Tomcat 连接到 JBoss 7.1.1 中的 EJB 时,JNDI 查找失败

php - 如何进行 MVC 表单 url 格式化?

api - Flutter 应用程序后端有哪些选项?