我正在尝试使用 Terremark 企业云中的一项 REST Web 服务。这是我所做的: 1) 获取 xsd 并生成 jaxb 工件 2) 发送 Rest 调用并让 Restclient 填充 Organizations 类。
ResponseEntity exchange = template.exchange("https://services.enterprisecloud.terremark.com/cloudapi/ecloud/organizations/",
HttpMethod.GET,
new HttpEntity(operation.getInput(), operation.getHeader()),
Organizations.class,
urlVariables);
我看到的错误是
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [com.dto.Organizations] and content type [application/vnd.tmrk.cloud.organization;type=collection]
在上述错误中,com.dto.Organizations 是由 JAXB 生成的 java 类。任何解决此问题的通用 Spring 指针也会有所帮助。
PS在spring调度程序中,我有以下内容:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean id="marshallingHttpMessageConverter"
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"
p:marshaller-ref="jaxb2Marshaller" p:unmarshaller-ref="jaxb2Marshaller" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
</list>
</property>
</bean>