Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans'(转)
|
今天把在线聊天室代码改了下, 想启动应用测试. 结果抛出一大堆异常: -------------------------------------------------------------------------------------------- org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 4 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
这就奇怪了.上午都还是好的. 突然说Spring配置文件不对. 根据异常说的: 就是'beans'没有定义. 这可能是命名空间有问题: ----------------------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 这定义是MyEclipse自动生成的. 应该不会有错吧.没办法, 只有上百度了. 几个网友也有我类似的问题. 其中一网友答案很是经典: Spring官网出了问题, 命名空间文件不能找到, 当然出问题了. 他的解决办法就是: 等Spring官网好了再试. 我也觉得这很有道理, 也在QQ群里给几个合作伙伴发消息说由于Srping官网出了问题, 聊天室不能调试. 但是越想越觉得很不安. 那岂不是所有的用到Spring的应用程序都要依赖Spring官网了? 这太危险了, 万一哪天官网彻底出问题了(当然这种可能是很小的了), 那所有的程序不都完了? 再说了命名空间文件可以下载下来放在本地的, 为什么一定要联网用呢? 那万一那天没有联网, 岂不不能做启动应用了? 在百度里找了很久, 没有找到解决办法. 上下Google找, 还不错, 找到了, 有位网友解决了此问题, 貌似很简单: --------------------------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> 为什么是这样, 网友说是版本问题, 我也不知道具体原因, 反正好了就好. |
造成以上的异常很常见,主要有两个方面:
第一,没有加入aop路径:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd //这里根据版本不一样,数字也不一样。 ">
第二,可能缺少lib文件:
看你的lib中有没有导入:com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
如果确认了以上两点,那么就OK。'
---------------------------------------------------------------------
在启动Spring时,报以下错误,如图:

原因是在xml中spring的xsd的版本配置的不一致,我使用的是spring-2.5.6,但配置文件中配的是3.0。改成如下即可:
另外,配置时,要注意配置文件的编码;否则当编译时,输出的编码和你的配置文件的编码不一致时,会产生文件乱码。
Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans'(转)的更多相关文章
- 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element
解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...
- Spring 异常 —— cvc-elt.1: Cannot find the declaration of element 'beans'
有个使用 Spring 的项目,运行时报错: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 5 ...
- spring cvc-elt.1: Cannot find the declaration of element 'beans'解决办法
转载自http://blog.csdn.net/legendj/article/details/9950963 今天在写spring aop示例的时候,在spring.xml文件中添加spring a ...
- spring 启动异常Failed to read candidate component class
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: ...
- (Spring加载xml时)org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
ApplicationContext ctx = new ClassPathXmlApplicationContext("test.xml");报错 在启动Spring时,报以下错 ...
- [key]严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener(Spring配置异常)
详细错误为: 严重: Exception sending context initialized event to listener instance of class org.springframe ...
- 从源码解析 Spring JDBC 异常抽象
初入学习 JDBC 操作数据库,想必大家都写过下面的代码: 数据库为:H2 如果需要处理特定 SQL 异常,比如 SQL 语句错误,这个时候我们应该怎么办? 查看 SQLException 源码,我们 ...
- spring启动,spring mvc ,要不要xml配置,基于注解配置
老项目是09-11年搞的,用的是spring+struts2,没有用注解,全xml配置.web.xml中也配置了一大堆. 现在启动新项目,在项目中用spring+springmvc ,主要用注解,也用 ...
- SpringCloud启动异常Stopping service [Tomcat]
问题场景: 领导让我搭建一套Jenkins实现自动化部署,项目是SpringCloud项目,配置的过程很顺利,给我提供了一台服务器做部署测试(服务器以前是做dev环境,很长时间没人用了) 我把所有项目 ...
随机推荐
- 1.1使用java数组,并开始封装我们自己的数组
今天感冒了,全身酸软无力,啥样不想做,就来学习吧,此节我们从初步使用java中提供的数组,然后分析相关情况,过渡到封装我们自己的数组. 一.我们先来感受一下java提供的数组,以整型数组(int[]) ...
- python中的open、close、read、write、len、exists
open()打开文件 close()关闭文件 read()读取文件内容 write()写入内容 len()检查文件内容长度 exists()检查文件是否存在 我们举一个例子,将上方的内容全部应用到实际 ...
- java 权重随机算法实现
import java.util.*; /** * 权重随机算法实现 * a b c d 对应权重范围 --- [0,1).[1,3).[3,6).[6,10) */ public class Ran ...
- zookeeper(1)初识zookeeper
一.zookeeper的安装 1.下载zookeeper(当然在安装zookeeper之前得先装好jdk,这里就不说了),版本自己随便选一个(后面我再说版本的问题),点击这里下载. 2.然后在usr下 ...
- RecyclerView下拉刷新上拉加载更多
现在Android里都建议用RecyclerView代替ListView和GridView,所以下拉刷新和上拉加载更多也需要实现.下拉刷新可以用SwipeRefreshLayout 包裹Recycle ...
- Map 接口
1.键值对存储一组对象 2.key值不能重复,value可以重复 3.具体的实现类,HashMap,treeMap,HashTable,LinkedHashMap ------------------ ...
- centos7下安装python3.7
记录在2018年最后一个工作日: Linux环境坑爹得要死,环境本身有python2和python3.7两个版本:安装django2的时候,发现默认是python2:把python软连接到python ...
- 1016B - Segment Occurrences(字符串的匹配)
题意:字符串a,字符串b,给你q个区间,让你求a的区间内字符串b出现了多少次 之前用的前缀数组做的,没想起来,发现这个其实也可以 #include<cstdio> #include< ...
- python中time模块和datetime模块
time模块和datetime模块 时间分为三种模式(time 模块) 时间戳 (time.time()) 格式化字符串 (time.strftime(%Y-%m-%d %H:%M:%S %p)) ...
- 实现一个简单的shell
使用已学习的各种C函数实现一个简单的交互式Shell,要求:1.给出提示符,让用户输入一行命令,识别程序名和参数并调用适当的exec函数执行程序,待执行完成后再次给出提示符.2.该程序可识别和处理以下 ...