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


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

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


异常信息json

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


后台controllorapp

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



网上不少的说法是引入以下两个包ide

        <dependency>this

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

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

        </dependency>servlet

        <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文件,并无引入上述的两个包。配置文件中加上后也是能够正常转化的。

相关文章
相关标签/搜索