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文件,並無引入上述的兩個包。配置文件中加上後也是能夠正常轉化的。