Jersey 2.25.1 HTTP STATUS 500 Error when using MediaType.APPLICATION_XML

馋奶兔 提交于 2019-12-11 05:28:30

问题


Since 2 days I am stuck with this issue and it is not going away.

A simple explanation what I want to do:

1) build a simple Restful web service using jersey 2.25.1 which displays XML as the output.

2) Deploy it on Tomcat

Just for Info My JSON and plain text restful webservice is working fine. I am only getting errors for XML when using @RootElement. I am using java 1.8, Jersy 2.25.1, tomcat 8.5

I am getting the below error again and again and don't understand how to resolve it:

I have tried these two examples as well but no luck:

1) https://www.mkyong.com/webservices/jax-rs/download-xml-with-jersey-jaxb/

I have tried multiple examples but still, This error shows up and I cannot resolve it. Can some one please explain me why this is coming up.

Thanks in Advance.


回答1:


Thank you everyone I fixed the issue... maybe this info will help everyone who is searching for the problem. The major problem was that I don't know for what reason If I make a new maven project on eclipse with Group Id org.glassfish.jersey.archetypes Artifact Id jersey-quickstart-webapp version 2.25.1, eclipse used to create a whole project with POM file as it suppose to and in this project if I even ran https://jersey.java.net/documentation/2.5.1/media.html#d0e7129 this simple jersey official demo, I was getting the same annotation error. I think in the POM file which eclipse create has a lot of things which I didn't needed and which must be overlapping with other things.

So in the above mkyong example I just added below dependency and it is now working just fine:

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.2.11</version>
</dependency>  

Thanks everyone for helping me out. :)




回答2:


You should be using @XmlRootElement annotation and not @RootElement. Also make sure you have the dependency jersey-media-jaxb in pom.xml or classpath



来源:https://stackoverflow.com/questions/43848782/jersey-2-25-1-http-status-500-error-when-using-mediatype-application-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!