码迷,mamicode.com
首页 > 编程语言 > 详细

spring mvc 使用@ResponseBody报错的解决方法

时间:2015-08-12 19:48:04      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:java @responsebody


spring 3.0 mvc在从后台向前台返回时要转化成json串,但页面上报了

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers


异常信息

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation


后台controllor

(= = RequestMethod.)
Map<StringObject> ((= = ) String custToken) {
    Map<StringObject> returnMap = HashMap<StringObject>() result = .queryYebAssets(custToken)returnMap.put(result)returnMap}



网上很多的说法是引入如下两个包

        <dependency>

            <groupId>org.codehaus.jackson</groupId>

            <artifactId>jackson-core-asl</artifactId>

        </dependency>

        <dependency>

            <groupId>org.codehaus.jackson</groupId>

            <artifactId>jackson-mapper-asl</artifactId>

        </dependency>

除此之外还要修改spring的配置文件里加入如下

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  <!-- Object->json -->
  <property name="messageConverters">
     <list>
        <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
     </list>
  </property>
</bean>


本项目中引入了其他的json文件,并没有引入上述的两个包。配置文件中加上后也是可以正常转化的。

spring mvc 使用@ResponseBody报错的解决方法

标签:java @responsebody

原文地址:http://mingsuper.blog.51cto.com/8269088/1684116

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!