java org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:找不到 MessageBodyWriter 响应对象的类型:媒体类型:应用程序/xml

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16162128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:04:43  来源:igfitidea点击:

org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: of media type: application/xml

javaresteasy

提问by user2093576

@POST
@Path("/getmethod")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_XML)
Response getMethod(SomeVO someVO);

In my *.ear I can see resteasy-jaxb-provider-2.2.0.GA.jar & resteasy-jaxrs-2.2.1.GA.jar both present but while trying to access this method, I am facing this error :

在我的*.ear 中,我可以看到 resteasy-jaxb-provider-2.2.0.GA.jar 和 resteasy-jaxrs-2.2.1.GA.jar 都存在,但是在尝试访问此方法时,我遇到了以下错误:

[org.jboss.resteasy.core.SynchronousDispatcher] (http-/0.0.0.0:8080-1) Failed executing POST //getmethod: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: *VO of media type: application/xml at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:216) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] at

[org.jboss.resteasy.core.SynchronousDispatcher] (http-/0.0.0.0:8080-1) 执行 POST 失败 //getmethod: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: 找不到 MessageBodyWriter 类型的响应对象: *媒体类型的VO:org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:216)的application/xml [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final -redhat-1] 在

org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:585)

org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:585)

[resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:506) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.1.Final-redhat-1.jar:1.0.1.Final-redhat-1] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.16.Final-redhat-1.jar:] at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_09]

[resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:506) [resteasy-jaxrs -2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] 在 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.3 .Final-redhat-1.jar:2.3.3.Final-redhat-1] 在 org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.3 .Final-redhat-1.jar:2.3.3.Final-redhat-1] 在 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.3 .Final-redhat-1.jar:2.3.3.Final-redhat-1] 在 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1] 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet -api_3.0_spec-1.0.1.Final-redhat-1.jar:1.0.1.Final-redhat-1] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0 .16.Final-redhat-1.jar:] 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org. apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContext161.java ) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org.jboss.as.web.security.SecurityContextAssociationValve。invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 在org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:155) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final- redhat-1.jar:] 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org.apache.catalina.connector .CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0 .16.Final-redhat-1.jar:] 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org.apache.tomcat.util.net.JioEndpoint$Worker.run(JioEndpoint.java:931) [jbossweb-7.0.16.Final- redhat-1.jar:] 在 java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_09]

回答by user2093576

I was not adding the annotation at the VO class attributes.

我没有在 VO 类属性中添加注释。

Sample:

样本:

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "user")
public class TestVo {

    String order;
    String serial;
    int number;

    @XmlElement
    public String getorder() {
        return order;
    }

    public void setorder(String order) {
        this.order = order;
    }

    @XmlElement
    public String getserial() {
        return serial;
    }

    public void setserial(String serial) {
        this.serial = serial;
    }

    @XmlAttribute
    public int getnumber() {
        return number;
    }

    public void setnumber(int number) {
        this.number = number;
    }

}

回答by Sreedhar GS

You can resolve it by refering below link.. He suggested to add org.jboss.resteasy resteasy-jaxb-provider 2.2.0.GA jar

您可以参考以下链接解决。他建议添加 org.jboss.resteasy resteasy-jaxb-provider 2.2.0.GA jar

http://www.mkyong.com/webservices/jax-rs/resteasy-could-not-find-messagebodywriter-for-response-object-of-typexx-of-media-type-applicationxml/

http://www.mkyong.com/webservices/jax-rs/resteasy-could-not-find-messagebodywriter-for-response-object-of-typexx-of-media-type-applicationxml/