我有一个像这样配置的jaxrs客户端:

<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>

但是,当我发送请求时,出现以下异常:
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类如下所示:
@Component
public interface RestProxy {

  @POST
  @Path("/getSomething")
  String getSomething(RequestObject RequestObject);
}

最佳答案

如果使用的是Jackson JSON库,则需要将这些xml标记添加到应用程序上下文中。

<jaxrs:providers>
<bean id="jacksonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />
</jaxrs:providers>

如果您正在使用其他库,则将该bean添加到providers标记中。希望有帮助!

07-25 22:46