最近遇到了我与 Spring 一起使用的 XStream 的问题。我们有一个 REST 应用程序,我们在其中使用 XStream 编组和解组 XML。我们已经配置如下图,
<bean id="xStreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="annotatedClasses">
<list><value>com.bestbuy.commerce.repobjects.OfflineOrderRepresentation</value></list>
</property>
<property name="autodetectAnnotations" value="true" />
</bean>
并且这个 XStreamMarshaller 被配置为 HttpMessageconverter,如图所示,
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list>
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="xStreamMarshaller" />
<property name="unmarshaller" ref="xStreamMarshaller" />
</bean>
</util:list>
</property>
</bean>
这里的问题是,当我发布正确的 XML 时,它应该与相应的 XStream 注释类“OfflineOrderRepresentation”匹配,但这是随机发生的,有时我收到语法不正确的消息,如果我重新启动服务器,问题会随机修复。
下面是我得到的错误日志,
[org.springframework.http.converter.xml.MarshallingHttpMessageConverter@712625b0]
[org.springframework.web.bind.annotation.support.HandlerMethodInvoker]
Reading [com.bestbuy.commerce.repobjects.OfflineOrderRepresentation]
[org.springframework.http.converter.xml.MarshallingHttpMessageConverter@712625b0]
[org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver]
[com.bestbuy.commerce.controllers.OrderController@799a92d1]:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read [class com.bestbuy.commerce.repobjects.OfflineOrderRepresentation];