springMVC4.0返回json数据的问题

来源:互联网 发布:coreldraw x5软件下载 编辑:程序博客网 时间:2024/05/20 18:00

springMVC4.0返回json数据的问题

我按照网上的方法在controller的方法体上配置了@ResponseBody,springmvc-servlet.xml中也配置了,如一下代码,最终成功返回。 
Xml代码  收藏代码
  1. <bean  
  2.         class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  3.         <property name="messageConverters">  
  4.             <list>  
  5.                 <ref bean="mappingJackson2HttpMessageConverter" />  
  6.             </list>  
  7.         </property>  
  8.     </bean>  
  9.     <bean id="mappingJackson2HttpMessageConverter"  
  10.         class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
  11.         <property name="supportedMediaTypes">  
  12.             <list>  
  13.                 <value>text/html;charset=UTF-8</value>  
  14.                 <value>text/json;charset=UTF-8</value>  
  15.                 <value>application/json;charset=UTF-8</value>  
  16.             </list>  
  17.         </property>  
  18.     </bean>  

但是,我想使用spring中的RedirectAttributes attr来在重定向中传递参数,按照说明在springmvc-servlet.xml中添加了<mvc:annotation-driven />,这个倒是能用了,但是json数据无法返回了,报了个异常 
Java代码  收藏代码
  1. type Status report  
  2.   
  3. message   
  4.   
  5. description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.  

不知道是哪出现了问题,请指教,不胜感激!! 

问题补充:问题已经解决,查看相关资料发现注册<mvc:annotation-driven />后,相当于自动装配了AnnotationMethodHandlerAdapter和DefaultAnnotationHandlerMapping两个bean,所以不能重复定义,而且spring3.2后,这两个方法已经过期推荐使用RequestMappingHandlerMapping和RequestMappingHandlerAdapter两个类,具体在哪个包,请自行查看!
0 0
原创粉丝点击