我正在 Spring 框架中开发一个 Web 应用程序。当请求作为 ModelAndView 响应类型提供服务时。它运行良好,但是当我尝试将响应作为 json 提供时,它会引发错误
例外
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.codehaus.jackson.map.SerializationConfig.isEnabled(Lorg/codehaus/jackson/map/SerializationConfig$Feature;)Z
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259)
根本原因
java.lang.NoSuchMethodError: org.codehaus.jackson.map.SerializationConfig.isEnabled(Lorg/codehaus/jackson/map/SerializationConfig$Feature;)Z
org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.writeInternal(MappingJacksonHttpMessageConverter.java:193)
控制器中的方法
@RequestMapping(value="/getFBFriendsList",method=RequestMethod.GET)<br/>
public @ResponseBody List<String> getStatesList(HttpServletRequest req){<br/>
List<String> statesList = null;
try{<br/>
statesList = new ArrayList<String>();<br/>
//..here i am getting states from datebase and adding to list<br/>
}<br/>
catch(Exception e){}<br/>
return statesList;
}
调度程序 Servlet 中的配置
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" >
<property name="supportedMediaTypes" value="application/json" />
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonHttpMessageConverter" />
</list>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
我正在使用杰克逊罐子
- 杰克逊核心 asl-1.9.0.jar
- jackson-mapper-asl-1.9.0.jar
- json-lib-0.9.jar
和 Spring 版本是 3.2.4