【发布时间】:2015-06-12 17:36:14
【问题描述】:
我正在尝试在客户端模式下使用 Jersy 2 将 XML 发布到服务器,但我总是遇到异常。
我的 pom 文件中只有一个依赖项:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.18</version>
</dependency>
我的 Java 代码:
public static void main(String... args) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080");
Entity<SimpleClass> entity = Entity.entity(new SimpleClass(), MediaType.APPLICATION_XML_TYPE);
target.request(MediaType.TEXT_XML_TYPE).post(entity);
}
@XmlRootElement(name = "test")
@XmlAccessorType(XmlAccessType.NONE)
public class SimpleClass {
@XmlElement(name = "hello")
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
例外:
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/xml, type=class jersey.SimpleClass, genericType=class jersey.SimpleClass.
我做错了什么?
【问题讨论】: