org.springframework.web.servlet.view.json.MappingJacksonJsonView

要点: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、异常解决完毕
 

展开阅读全文

SpringMVC配置文件报错MappingJacksonJsonView

05-19
严重: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.json.MappingJacksonJsonView] for bean with name 'userListJson' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.json.MappingJacksonJsonView Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.json.MappingJacksonJsonView] for bean with name 'userListJson' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.json.MappingJacksonJsonView 代码: @RequestMapping(value = "/showUserListByJson") public String showUserListInJson(ModelMap mm) { List<Person> userList = new ArrayList<Person>(); Person user1 = new Person(); user1.setUsername("tom"); user1.setPassword("汤姆"); Person user2 = new Person(); user2.setUsername("john"); user2.setPassword("约翰"); userList.add(user1); userList.add(user2); mm.addAttribute("userList", userList); return "userListJson"; } <!-- XMl及JSON视图解析器配置 --> <bean id="userListJson" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" p:renderedAttributes="userList" />

Windows版YOLOv4目标检测实战:训练自己的数据集

04-26
©️2020 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值