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文件,并没有引入上述的两个包。配置文件中加上后也是可以正常转化的。
时间: 2024-09-30 20:51:16