首页 新闻 会员 周边 捐助

spring MVC 解析 xml

-1
悬赏园豆:50 [已关闭问题] 关闭于 2014-02-27 12:13

SpringMVC解析xml不成功,具体问题如下:

controller代码如下:

......

@RequestMapping(value = "/verifyMessages",method = RequestMethod.POST)
public String recieveMessages(@RequestBody InMessage inMessage)

System.out.println(inMessage.getCreateTime());
System.out.println(inMessage.getMsgType());
// System.out.println(text);
return null;
}

.......

InMessage 代码如下:

@XStreamAlias("xml")
public class InMessage {

private String ToUserName; 

......

//定义了一些成员变量和set,get方法

 

配置文件如下:

.......

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
p:messageConverters-ref="messageConverters"/>

<util:list id="messageConverters">
<!--<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
-->
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"
p:marshaller-ref="xmlMarshaller"
p:unmarshaller-ref="xmlMarshaller">
</bean>
</util:list>


<!-- 声明Marshaller,使用XStream技术 -->
<bean id="xmlMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"
p:autodetectAnnotations="true">
<property name="streamDriver">
<bean class="com.thoughtworks.xstream.io.xml.StaxDriver"/>
</property>
<property name="annotatedClasses">
<list>
<value>models.entity.InMessage</value>
</list>
</property>
</bean>

......

curl测试语句如下:

curl -H "Accept:application/xml" -H "Content-Type:application/xml" -d "<xml></xml>" http://localhost:8080/Weixin_CSS_IntelligentResponse/intelligentresponse/verifyMessages

 

错误代码:HTTP Status 415

错误原因: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

 

xml解析jar包:xpp3_min-1.1.3.4.O.jar,xstream-1.4.5.jar

 

controller如果把接收的参数改为用String 接收可以顺利接收, 但是xml格式的就始终不能在接收时直接转换成java类,困扰我好几天了,有木有哪位高人可以解答,万分感谢!

紫晶碧瞳的主页 紫晶碧瞳 | 菜鸟二级 | 园豆:206
提问于:2014-02-20 20:01
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册