我的客户端应用程序中有此代码
Client c = ClientBuilder.newClient();
WebTarget t = c.target("http://localhost:8080/PlayerRest/r/Player");
Player p = new Player();
p.setPid(new Integer(954));
p.setNickname("testForPUT");
t.request(MediaType.APPLICATION_XML).put(Entity.entity(p, MediaType.APPLICATION_XML));
这给了我多汁的例外:
Exception in thread "main" org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/xml, type=class Player, genericType=class Player.
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:227)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1139)
at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:495)
at org.glassfish.jersey.client.HttpUrlConnector._apply(HttpUrlConnector.java:270)
at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:182)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:227)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:655)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:652)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:422)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:652)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:412)
at org.glassfish.jersey.client.JerseyInvocation$Builder.put(JerseyInvocation.java:306)
at ClientRest.main(ClientRest.java:20)
这可能是什么问题?
谢谢!
答案 0 :(得分:0)
您需要添加JAXB支持
从版本2.16开始,所有JAX-B提供程序都捆绑在一个单独的模块中。
在项目中添加jersey-media-jaxb jar,或者可以在pom.xml中为所需的jar添加依赖
QString