使用 MediaType.APPLICATION_XML 时 Jersey 2.25.1 HTTP STATUS 500 错误 [英] Jersey 2.25.1 HTTP STATUS 500 Error when using MediaType.APPLICATION_XML
问题描述
2 天以来,我一直被这个问题困扰,而且它不会消失.
Since 2 days I am stuck with this issue and it is not going away.
简单说明我想做什么:
1) 使用 jersey 2.25.1 构建一个简单的 Restful Web 服务,它显示 XML 作为输出.
1) build a simple Restful web service using jersey 2.25.1 which displays XML as the output.
2) 部署在Tomcat上
2) Deploy it on Tomcat
仅供参考我的 JSON 和纯文本 Restful Web 服务运行良好.使用@RootElement 时,我只收到 XML 错误.我正在使用 java 1.8、Jersy 2.25.1、tomcat 8.5
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.
提前致谢.
推荐答案
谢谢大家 我解决了这个问题...也许这些信息会对所有正在寻找问题的人有所帮助.主要问题是我不知道出于什么原因如果我使用 Group Id org.glassfish.jersey.archetypes Artifact Id jersey 在 Eclipse 上创建一个新的 maven 项目-quickstart-webapp version 2.25.1,eclipse 过去常常使用 POM 文件创建一个完整的项目,如果我什至运行 https://jersey.java.net/documentation/2.5.1/media.html#d0e7129这个简单的球衣官方演示,我得到了同样的注释错误.我认为在 eclipse 创建的 POM 文件中有很多我不需要的东西,并且必须与其他东西重叠.
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.
因此,在上面的 mkyong 示例中,我刚刚添加了以下依赖项,现在工作正常:
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>
感谢大家帮助我.:)
这篇关于使用 MediaType.APPLICATION_XML 时 Jersey 2.25.1 HTTP STATUS 500 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!