Spring10种常见异常解决方法
然而在使用过程中,遇到过很多的常见异常,我在这里总结一下,大家共勉。
一、找不到配置文件的异常
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML
- document from class path resource [com/herman/ss/controller]; nested exception is java.io.FileNotFoundException:
- class path resource [com/herman/ss/controller] cannot be opened because it does not exist
解释:这个的意思是说,没有找配置文件为controller的xml,修改一下配置文件名字即可。
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:com/herman/ss/config/testAjax.xml</param-value>
- </init-param>
二、在xml中配置的命名空间找不到对应的Schema的异常
- nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict,
- but no declaration can be found for element 'util:list'.
xmlns:util="http://www.springframework.org/schema/util" 去掉,因为schema中不存在util命名
三、找不到jackson.jar的异常
- StandardWrapper.Throwable
- java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonProcessingException
缺少jackson的jar包,导入jackson-all-1.9.5.jar即可
四、bean不是唯一的异常
- org.springframework.beans.factory.NoUniqueBeanDefinitionException:
- No qualifying bean of type [com.herman.ss.pojo.Person] is defined:
- expected single matching bean but found 7: person0,person1,person2,person3,person4,person5,person6
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:313)
- at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
- at com.herman.ss.test.Test0.test1(Test0.java:35)
- at com.herman.ss.test.Test0.main(Test0.java:111)
这个异常是说,一个类配置了多个bean之后,我们还在使用ctx.getBean(Person.class);方法,即根据bean的类映射去获取bean对象。这个时候返回的bean对象不是唯一的,有多个bean对象。解决方法,就是根据bean的id去获取bean对象。
五、缺少日志jar包
- java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
这个问题是说,项目中缺少spring依赖的jar包文件。解决方案:加入commons-logging-1.1.3.jar即可。
六、找不到bean异常
- 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包
- 严重: Error loading WebappClassLoader
- context: /Struts_Spring_Project
- delegate: false
- repositories:
- /WEB-INF/classes/
- ----------> Parent Classloader:
- org.apache.catalina.loader.StandardClassLoader@b33d0a
- org.springframework.web.servlet.DispatcherServlet
- 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包
- java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
- 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包
- java.lang.NoClassDefFoundError: org/springframework/expression/ExpressionParser
- java.lang.ClassNotFoundException: org.springframework.expression.ExpressionParser
解决方案:在项目中加入spring的expression架包即可。如我的spring版本为4.0.6的,那么就把spring-expression-4.0.6.RELEASE.jar添加进去即可。
九、bean的名字name或者id或者别名alias已经存在
- org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
- Configuration problem: Bean name 'a' is already used in this <beans> element
解决方法:把重复的名字改个名字即可。
十、bean的自动加载找不到相对应的bean问题
- 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>包下面用*匹配
Spring10种常见异常解决方法的更多相关文章
- Spring学习总结(14)——Spring10种常见异常解决方法
在程序员生涯当中,提到最多的应该就是SSH三大框架了.作为第一大框架的Spring框架,我们经常使用. 然而在使用过程中,遇到过很多的常见异常,我在这里总结一下,大家共勉. 一.找不到配置文件的异常 ...
- Ubuntu几种常见乱码解决方法
一.网页中的flash乱码: ubuntu默认浏览器是Firefox,但是Ubuntu默认不安装像flash这种带版权的软件,所以当你浏览像youku或网页播放器时,这种带有 flash ...
- C#常见错误解决方法
1.能提供Visual Studio开发工具包吗? 解决方法: Visual Studio 2017开发环境下载地址: https://www.visualstudio.com/zh-hans/dow ...
- Android 异常解决方法【汇总】
(1)异常:Android中引入第三方Jar包的方法(Java.lang.NoClassDefFoundError解决办法) 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方 ...
- Hbase常见错误解决方法
Hbase常见错误解决方法 原文转载至:https://www.jianshu.com/p/5fd74812c56c 我是通过maven管理的依赖,直接修改maven依赖中hbase的版本就可以了 ...
- Spark程序运行常见错误解决方法以及优化
转载自:http://bigdata.51cto.com/art/201704/536499.htm Spark程序运行常见错误解决方法以及优化 task倾斜原因比较多,网络io,cpu,mem都有可 ...
- SVN Attempted to lock an already-locked dir异常解决方法
Attempted to lock an already-locked dir异常解决方法 eclipse或myeclipse用svn提交的时候报错: Attempted to lock an alr ...
- Tomcat安装教程及常见错误解决方法
目录 Tomcat安装教程及常见错误解决方法 一.安装前准备 ·熟悉自己电脑的操作系统版本(32位or64位) ·保证电脑上已经装好JDK,并且已经设置好环境变量. 二.Tomcat安装教程(以Tom ...
- SQLMAP注入教程-11种常见SQLMAP使用方法详解
sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了.今天把我一直 ...
随机推荐
- ASP.NET常用页面指令
1.<%@Page "属性"="值"%>指令 AutoEventWireup:指定页的事件是否自动绑定,默认值true为启用自动绑定. CodeBe ...
- Linq学习笔记(转)
开始Linq前你要知道的 扩展方法 顾名思义就是对现有类进行扩展的的方法,扩展方法可以在不修改现有类的情况下,为现有类增加公共的接口(不是C#中的interface). 扩展方法本质上是一个静态方法, ...
- 阿里云消息队列MQ_HTTP接入 for .NetCore 简单例子
, , )).TotalMilliseconds; , , )).TotalMilliseconds; ) ...
- Nginx+keepalived双机热备(主主模式)
之前已经介绍了Nginx+Keepalived双机热备的主从模式,今天在此基础上说下主主模式的配置. 由之前的配置信息可知:master机器(master-node):103.110.98.14/19 ...
- keytool命令记录
1.生成服务器端私钥kserver.keystore文件 2.根据私钥,导出服务器端安全证书 3.将服务器端证书,导入到客户端的Trust KeyStore中 4.生成客户端私钥kclient.key ...
- Visual Studio2012打开时弹出“遇到异常:这可能是由某个扩展导致的”错误的解决办法
Visual Studio2012打开时弹出"遇到异常:这可能是由某个扩展导致的"错误的解决办法: 具体问题如下: 分析原因:网上搜集了以下,出现异常的原因是安装了第三方控件,然后 ...
- PCL 库安装
参考资料: http://www.cnblogs.com/newpanderking/articles/4022322.html VS2010+PCL配置 PCL共有两种安装方式 安全安装版,个人配置 ...
- 使Eclipse符合Java编程规范
编程规范是很重要的东西,能让团队的代码易于阅读和维护,也便于日后的功能扩展. 工欲善其事必先利其器!作为一个Java程序员,与Eclipse打交道可能是一辈子的事情.将Eclipse设置为符合公司编程 ...
- Spring IOC 源码浅析
控制反转(Inversion of Control,英文缩写为IoC)是一个重要的面向对象编程的法则来削减计算机程序的耦合问题,也是轻量级的Spring框架的核心. 控制反转一般分为两种类型,依赖注入 ...
- 高性能JavaScript 达夫设备
前言 在<高性能JavaScript>一书的第四章算法和流程控制中,提到了减少迭代次数加速程序的策略—达夫设备(Duff's device).达夫设备本身很好理解,但是其效果是否真的像书中 ...