2015-06-12 85 views
1

我試圖在客戶端模式中使用Jersy 2將XML發佈到服務器,但我總是得到一個異常。Jersy 2 Client + JAXB(MessageBodyWriter未找到)

我有隻有一個依賴於我的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. 

我做錯了嗎?

+0

的可能重複[新澤西版本問題:化MessageBodyReader找不到媒體類型=應用程序/ XML( http://stackoverflow.com/questions/30754641/jersey-version-issue-messagebodyreader-not-found-for-media-type-application-xml) –

回答

相關問題