JAX-RS JAXB JSON响应不工作(MessageBodyProviderNotFoundException)
我一直在研究如何创建JAX Restful服务。。。使用此处提供的指南- 如第2.3.2节所述,我在Maven中添加了以下依赖项-JAX-RS JAXB JSON响应不工作(MessageBodyProviderNotFoundException),json,jaxb,jax-rs,Json,Jaxb,Jax Rs,我一直在研究如何创建JAX Restful服务。。。使用此处提供的指南- 如第2.3.2节所述,我在Maven中添加了以下依赖项- <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.0</versi
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.0</version>
</dependency>
PatientController.java-
@Path("/ManagePatient")
public class PatientController {
@GET
@Path("/getPatient")
@Produces(MediaType.APPLICATION_XML)
public Patient printPatient() {
System.out.println("Hello.... from the PatientController");
Patient ptnt = new Patient();
ptnt.setPatientFName("FirstN");
ptnt.setPatientLName("LName");
ptnt.setPatientAge(30);
ptnt.setPatientSex("M");
ptnt.setPatientParentSpouse("ParentSpuse");
ptnt.setPatientQual("engg");
ptnt.setPatientOccupation("software");
ptnt.setPatientComments("comments here");
System.out.println("Patient = " + ptnt);
//return ptnt.toString();
return ptnt;
}
当我试图通过浏览器@localhost:8080/HMS\u Web/services/ManagePatient/getPatient访问此文件时
我越来越
javax.servlet.ServletException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html, type=class com.hms.app.ui.beans.Patient, genericType=class com.hms.app.ui.beans.Patient.
我在日志中也看到了下面的警告-
WARNING: A provider com.hms.app.ui.beans.Patient registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.hms.app.ui.beans.Patient will be ignored.
如果Jersey 2.0支持Jersey指南中提到的基于JAXB的xml或json支持@8.1.1.2.基于JAXB的json支持,我不确定为什么会收到提供程序错误
任何JAX-WS专家都能帮助我理解并指导我如何解决这种情况吗
提前感谢您您正在通过浏览器访问服务,因此您的PatientController将尝试将响应呈现为html,我想这就是
javax.servlet.ServletException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html, type=class com.hms.app.ui.beans.Patient, genericType=class com.hms.app.ui.beans.Patient.
尝试通过jersey客户端api将该服务汇总如下:
WebTarget webTarget = client.target("http://localhost:8080/HMS_Web/services/ManagePatient/getPatient");
Patient patient = webTarget.request(MediaType.APPLICATION_XML_TYPE).get(Patient.class);
有关警告:
WARNING: A provider com.hms.app.ui.beans.Patient registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.hms.app.ui.beans.Patient will be ignored.
我认为你应该删除:
add(Patient.class);
在您的MyApp中。患者只是一个POJO,它既不是资源也不是提供者。非常感谢。关于使用浏览器的问题,我的措辞是错误的,我正在使用cURL检索xml或json。。。在检索xml时-我得到HTTP 500响应(我正试图找出原因),在检索json时-我得到MessageBodyWriter未找到媒体类型=application/json。正在为此添加moxy。非常感谢您的回复。只要将Genson添加到您的类路径中,一切都会正常工作。它还将自动支持jaxb注释。
WebTarget webTarget = client.target("http://localhost:8080/HMS_Web/services/ManagePatient/getPatient");
Patient patient = webTarget.request(MediaType.APPLICATION_XML_TYPE).get(Patient.class);
WARNING: A provider com.hms.app.ui.beans.Patient registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.hms.app.ui.beans.Patient will be ignored.
add(Patient.class);