要点:Spring升级到4后,JACKSON的包及处理类变了
1、异常信息
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.view.ContentNegotiatingViewResolver#0' defined in class path resource [spring-mvc.xml]: Cannot create inner bean 'org.springframework.web.servlet.view.json.MappingJacksonJsonView#5cde8f62' of type [org.springframework.web.servlet.view.json.MappingJacksonJsonView] while setting bean property 'defaultViews' with key [0]; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.json.MappingJacksonJsonView] for bean with name 'org.springframework.web.servlet.view.json.MappingJacksonJsonView#5cde8f62' defined in class path resource [spring-mvc.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.json.MappingJacksonJsonView
2、异常分析
思路:查看自己的Spring版本
依据:不同的版本处理JSON的类不一样,具体如下
spring3.x版本处理“将ModelAndView里的数据变成JSON”的类
org.springframework.web.servlet.view.json.MappingJacksonJsonView
spring4.x版本处理“将ModelAndView里的数据变成JSON”的类
org.springframework.web.servlet.view.json.MappingJackson2JsonView