我在使用 RestTemplate 访问 REST 服务时遇到问题。我已经设法使用 MarshallingConverter 访问另一项服务,并且一切正常。我已经从我收到的 XSD 架构中复制了这个功能并生成了模型类。但是我得到一个例外,没有找到合适的转换器。这是我的配置(如果重要的话,我将 Spring 3.0.6 与 Vaadin 结合使用):
<bean id="marshallingConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="jaxbMarshaller" />
<property name="unmarshaller" ref="jaxbMarshaller" />
</bean>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
... here are my model classes ...
</list>
</property>
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<ref bean="marshallingConverter" />
</list>
</property>
</bean>
RestTemplate 在我的服务客户端类实现中自动装配。我在这里想念什么?我检查了响应并且内容类型设置为 application/xml 并且模型类是自动生成的,所以配置应该是正确的。谢谢你的帮助。