本文介绍了JAXRS客户端找不到邮件正文编写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样配置的jaxrs客户端:
I have a jaxrs client configured like this:
<jaxrs:client id="opaRestProxy" name="opaRestProxy"
address="${endpoint}" serviceClass="com.test.RestProxy"
inheritHeaders="true" threadSafe="true">
<jaxrs:headers>
<entry key="Accept" value="application/json" />
<entry key="Content-Type" value="application/json" />
</jaxrs:headers>
</jaxrs:client>
但是当我发送请求时,我得到以下异常:
But when I send a request I get the following exception:
Caused by: org.apache.cxf.interceptor.Fault: .No message body writer has been found for class : class com.test.RequestObject, ContentType : application/json.
at org.apache.cxf.jaxrs.client.ClientProxyImpl$BodyWriter.handleMessage(ClientProxyImpl.java:646)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:527)
... 47 more
我的RestProxy类看起来像这样:
My RestProxy class looks like this:
@Component
public interface RestProxy {
@POST
@Path("/getSomething")
String getSomething(RequestObject RequestObject);
}
推荐答案
如果您使用的是Jackson JSON库需要将这些xml标记添加到应用程序上下文中。
If you are using Jackson JSON library you need to add these xml tags to your application context.
<jaxrs:providers>
<bean id="jacksonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
</jaxrs:providers>
如果您正在使用任何其他库,请将该bean添加到providers标记。希望有所帮助!
If you are using any other library add that bean to the providers tag. Hope that helps!
这篇关于JAXRS客户端找不到邮件正文编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!