RESTEasy-MessageBodyWriter找不到任何媒体类型

时间:2018-10-29 10:09:14

标签: xml jboss resteasy

我遇到Jboss和Resteasy的问题。我只是想通过REST服务返回XML对象。方法尝试返回Response对象时,问题就出现了。

Jboss告诉我,MessageBodyWriter找不到任何类型的对象的“ application / xml”媒体类型。我尝试了其他媒体类型,例如“ application / json”,“ text / plain”等,它给了我同样的错误。我也尝试返回对象而不在“响应”中进行设置,但出现相同的错误。

好像jboss看不到JAXB Provider,但是为什么呢?声明:我不使用Maven。我在构建路径中有一堆库,并在运行时需要时通过jboss-deployment-structure.xml对其进行访问。我知道它有效,因为那是我加载“ resteasy-jarxs”的方式。

要返回的对象具有JAXB批注。我正在尝试一些互联网示例,但这似乎是不可能的。

休息班

@Path("/user-management")
public class PruebaREST
{
    @GET
    @Path("/users/{id}")
    @Produces("application/xml")
    public Response getUserById(@PathParam("id") Integer id)
    {
        ObjetoPrueba user = new ObjetoPrueba();
        user.setId(id);
        user.setFirstName("aaaa");
        user.setLastName("bbbb"); 

        return Response.status(200).entity(user).build();
    }
} 

jboss-deployment-structure.xml:

<dependencies>  
            ...
            ...
            ...
            ...
   <module name="org.jboss.resteasy.resteasy-jaxb-provider" export="true"/>
   <module name="org.jboss.resteasy.resteasy-jaxrs" export="true"/>
</dependencies>

要返回的对象:

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

@XmlRootElement
public class ObjetoPrueba {

    private int id;

    private String firstName;

    private String lastName;

    @XmlAttribute
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    @XmlElement
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @XmlElement
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

还有友好错误:

HTTP Status 500 - Could not find MessageBodyWriter for response object of type: net.bizkaia.u2bi000m.rest.ObjetoPrueba of media type: application/xml

我想念什么?预先感谢。

0 个答案:

没有答案
相关问题