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注入另一方面就是手工党了,这个就另当别论了.今天把我一直 ...
随机推荐
- java 24 - 10 GUI 之 四则预算的数据校验
我想要在校验的过程中,如果输入到操作数中的不是数字,则弹出提醒框: 类 JOptionPane 有助于方便地弹出要求用户提供值或向其发出通知的标准对话框 方法名 描述 showConfirmDial ...
- bzoj2548[Cstc2002]灭鼠行动
Description 最近,有一些繁殖力很强的老鼠在下水道非常猖獗,灭鼠特工队正在计划消灭这些老鼠.下水道只有东西方向和南北方向的管道,如图所示. 灭鼠特工队的队员拥有强大的武器.他们将在某些时刻t ...
- uva10160 Servicing Stations
The input consists of more than one description of town (but totally, less than ten descriptions). E ...
- vue组件的配置属性
vue组件的声明语法: Vue.component('component-name',{ template:'<p>段落{{prop1}} {{prop2}}</p>', da ...
- HTML 学习笔记 JavaScript (节点)
HTML 节点: HTML DOM定义了所有HTML元素的对象和属性 以及访问它们的方法. HTML DOM是关于如何获取 修改 添加 或 删除HTML元素的标准. 在js中通过document这个对 ...
- zlog学习笔记(mdc)
mdc.h #ifndef __zlog_mdc_h #define __zlog_mdc_h #include "zc_defs.h" typedef struct zlog_m ...
- jQuery动态产生的铵钮怎样实现事件处理
在ASP.NET MVC环境中,实现一个小功能,就是希望使用jQuery动态一个铵钮,并让用户能执行这个铵钮的click事件.为了更好的理解与对比,Insus.NET在视图中先写一个静态的,执行相似的 ...
- single-write-database-connection
http://ithare.com/ultimate-db-heresy-single-db-connection-part-i-performance-part-ii-scalability-to- ...
- JAVA CDI 学习(5) - 如何向RESTFul Service中注入EJB实例
RESTFul Service中如果要注入EJB实例,常规的@Inject将不起作用,在Jboss中,应用甚至都启动不起来(因为@Inject注入失败),解决方法很简单:将@Inject换成@EJB ...
- ubuntu mysql 更改IP导致mysql无法启动
bind-address = 127.0.0.1 => bind-address= 136.129.20.168 IP要这么改 这么改远程连不上,那么需要把这行整行注释掉,重启MYSQL,tel ...