使用MediaType.APPLICATION_XML时,Jersey 2.25.1 HTTP STATUS 500错误 [英] Jersey 2.25.1 HTTP STATUS 500 Error when using MediaType.APPLICATION_XML

查看:95
本文介绍了使用MediaType.APPLICATION_XML时,Jersey 2.25.1 HTTP STATUS 500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自2天以来,我一直在坚持这个问题,而且这个问题一直没有消失.

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

一个简单的解释,我想做什么:

A simple explanation what I want to do:

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和纯文本静态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- quickstart-webapp 版本 2.25.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.

因此在上面的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>  

感谢大家对我的帮助. :)

Thanks everyone for helping me out. :)

这篇关于使用MediaType.APPLICATION_XML时,Jersey 2.25.1 HTTP STATUS 500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆