在程序员生涯当中,提到最多的应该就是SSH三大框架了。作为第一大框架的Spring框架,我们经常使用。
然而在使用过程中,遇到过很多的常见异常,我在这里总结一下,大家共勉。
一、找不到配置文件的异常
  1. org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML
  2. document from class path resource [com/herman/ss/controller]; nested exception is java.io.FileNotFoundException:
  3. class path resource [com/herman/ss/controller] cannot be opened because it does not exist
解释:这个的意思是说,没有找配置文件为controller的xml,修改一下配置文件名字即可。
  1. <init-param>
  2. <param-name>contextConfigLocation</param-name>
  3. <param-value>classpath:com/herman/ss/config/testAjax.xml</param-value>
  4. </init-param>
二、在xml中配置的命名空间找不到对应的Schema的异常
  1. nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict,
  2. but no declaration can be found for element 'util:list'.
xmlns:util="http://www.springframework.org/schema/util" 去掉,因为schema中不存在util命名
三、找不到jackson.jar的异常
  1. StandardWrapper.Throwable
  2. java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonProcessingException
缺少jackson的jar包,导入jackson-all-1.9.5.jar即可
四、bean不是唯一的异常
  1. org.springframework.beans.factory.NoUniqueBeanDefinitionException:
  2. No qualifying bean of type [com.herman.ss.pojo.Person] is defined:
  3. expected single matching bean but found 7: person0,person1,person2,person3,person4,person5,person6
  4. at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:313)
  5. at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
  6. at com.herman.ss.test.Test0.test1(Test0.java:35)
  7. at com.herman.ss.test.Test0.main(Test0.java:111)
这个异常是说,一个类配置了多个bean之后,我们还在使用ctx.getBean(Person.class);方法,即根据bean的类映射去获取bean对象。这个时候返回的bean对象不是唯一的,有多个bean对象。解决方法,就是根据bean的id去获取bean对象。
五、缺少日志jar包
  1. java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
  2. Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
这个问题是说,项目中缺少spring依赖的jar包文件。解决方案:加入commons-logging-1.1.3.jar即可。
六、找不到bean异常
  1. org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'filter2' is defined
这个问题是说,项目中找不到name为filter2的bean。说白了就是在applicationContext.xml中找不到id为filter2的bean,配置一下即可。
六、缺少spring-webmvc-4.0.6.RELEASE.jar包
  1. 严重: Error loading WebappClassLoader
  2. context: /Struts_Spring_Project
  3. delegate: false
  4. repositories:
  5. /WEB-INF/classes/
  6. ----------> Parent Classloader:
  7. org.apache.catalina.loader.StandardClassLoader@b33d0a
  8. org.springframework.web.servlet.DispatcherServlet
  9. java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
解决方案:在项目中加入spring的mvc架包即可。如我的spring版本为4.0.6的,那么就把spring-webmvc-4.0.6.RELEASE.jar添加进去即可。
七、缺少spring-aop-4.0.6.RELEASE.jar包
  1. java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
  2. java.lang.ClassNotFoundException: org.springframework.aop.TargetSource
解决方案:在项目中加入spring的aop架包即可。如我的spring版本为4.0.6的,那么就把spring-aop-4.0.6.RELEASE.jar添加进去即可。
八、缺少spring-expression-4.0.6.RELEASE.jar包
  1. java.lang.NoClassDefFoundError: org/springframework/expression/ExpressionParser
  2. java.lang.ClassNotFoundException: org.springframework.expression.ExpressionParser
解决方案:在项目中加入spring的expression架包即可。如我的spring版本为4.0.6的,那么就把spring-expression-4.0.6.RELEASE.jar添加进去即可。
九、bean的名字name或者id或者别名alias已经存在
  1. org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
  2. Configuration problem: Bean name 'a' is already used in this <beans> element
解决方法:把重复的名字改个名字即可。
十、bean的自动加载找不到相对应的bean问题
  1. org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yyc.ym.biz.YycBiz] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
解决方法:在配置文件中的<beans>根节点下加default-autowire="byName" default-lazy-init="true"或者<context:component-scan base-package="com.xxx.dao.*"></context:component-scan>包下面用*匹配

Spring学习总结(14)——Spring10种常见异常解决方法的更多相关文章

  1. Spring10种常见异常解决方法

    在程序员生涯当中,提到最多的应该就是SSH三大框架了.作为第一大框架的Spring框架,我们经常使用. 然而在使用过程中,遇到过很多的常见异常,我在这里总结一下,大家共勉. 一.找不到配置文件的异常 ...

  2. spring集成Junit做单元测试及常见异常解决办法

    spring-test依赖包 <!--Spring-test --> <!-- https://mvnrepository.com/artifact/org.springframew ...

  3. Ubuntu几种常见乱码解决方法

    一.网页中的flash乱码:        ubuntu默认浏览器是Firefox,但是Ubuntu默认不安装像flash这种带版权的软件,所以当你浏览像youku或网页播放器时,这种带有 flash ...

  4. orcal 数据库 maven架构 ssh框架 的全xml环境模版 及常见异常解决

    创建maven项目后,毫不犹豫,超简单傻瓜式搞定dependencies(pom.xml 就是maven的依赖管理),这样你就有了所有你要的包 <project xmlns="http ...

  5. SQLMAP注入教程-11种常见SQLMAP使用方法详解

    sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了.今天把我一直 ...

  6. [转]11种常见sqlmap使用方法详解

    sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了.今天把我一直 ...

  7. C#常见错误解决方法

    1.能提供Visual Studio开发工具包吗? 解决方法: Visual Studio 2017开发环境下载地址: https://www.visualstudio.com/zh-hans/dow ...

  8. Android 异常解决方法【汇总】

    (1)异常:Android中引入第三方Jar包的方法(Java.lang.NoClassDefFoundError解决办法) 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方 ...

  9. Tomcat安装教程及常见错误解决方法

    目录 Tomcat安装教程及常见错误解决方法 一.安装前准备 ·熟悉自己电脑的操作系统版本(32位or64位) ·保证电脑上已经装好JDK,并且已经设置好环境变量. 二.Tomcat安装教程(以Tom ...

随机推荐

  1. 数据库常用sql语句积累

    组合一个新表 select p.*,(select value from as_info where key = 'v51_products') as v51_products from AP_POR ...

  2. CF1027F Session in BSU (并查集+树上构造)

    题目大意:你可以在第$ai$天或者第$bi$天进行第$i$场考试,每天最多进行一场考试,求把所有考试都考完的最早结束时间 由于天数可能很大,需要离散 把问题抽象成一棵树,每个点最多被"分配& ...

  3. Uboot优美代码赏析1:目录结构和malkefile分析

    Uboot优美代码赏析1:目录结构和malkefile分析 关于Uboot自己选的版本是目前最新的2011.06,官方网址为:http://www.denx.de/wiki/U-Boot/WebHom ...

  4. 2019-03-20 用SSIS把Excel中的数据导出来保存到SQLServer中

    Control Flow 1.配置 好 图形 2.去变量那 配置好 文件路径 和 存储过程 3.在SQL Server创建对应的存储过程,该存储过程的功能是每次导入是清空原有的数据 4.如果不懂的参考 ...

  5. 如何让Jboss的debug在myeclise上运行

    1.在windows下运行jboss的debug.bat 看见监听的端口 2.打开myeclipse 点击选择 ①你要配置的名字(随意) ②myeclipse中选中该项目 ③jboss的启动的ip地址 ...

  6. VUE:class与style强制绑定

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. UVA 12507 Kingdoms

    D - Kingdoms Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu A kingdom ha ...

  8. NYIST 860 又见01背包

    又见01背包时间限制:1000 ms | 内存限制:65535 KB难度:3 描述 有n个重量和价值分别为wi 和 vi 的 物品,从这些物品中选择总重量不超过 W 的物品,求所有挑选方案中物品价值总 ...

  9. Android仿QQ ios dialog,仿QQ退出向上菜单

    Android仿QQ ios dialog,仿QQ退出向上菜单 EasyDialog两种模式 仿QQ退出向上菜单,自己定义向上菜单              github地址:https://gith ...

  10. HDU 4372

    想了很久,终于想到了.... 向后看到F,向前看到B,假如把N-1个楼分成F+B个组,则把每个组最高的楼作为看到的楼,那么,其实在确定每一组的最高楼时,左边或右边的最高楼的顺序已经确定了.由于是排列数 ...