最近我遇到了与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];