要點: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
3、異常根源
4、處理異常:匹配Spring版本對應的處理類
5、異常解決完畢