今天把在线聊天室代码改了下, 想启动应用测试. 结果抛出一大堆异常:
--------------------------------------------------------------------------------------------
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官网好了再试.
最后google了好几次才找到原因
- <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
- classpath:/org/springframework/beans/factory/xml/spring-beans-2.0.xsd"
- default-lazy-init="true">
需要增加“classpath:/”
原帖 http://www.jnan.org/archives/2010/12/cannot-find-the-declaration-of-element-beans.html
Spring配置文件xsi:schemaLocation无法解析导致启动失败的解决方案
今天向服务器部署一个console java app之后,启动时发现程序出现异常:
Exception in thread “main” org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 10 in XML document from class path resource [app-config.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element ‘beans’.
然后去看看app-config.xml里的schema声明部分,是这样写的:
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:context=”http://www.springframework.org/schema/context”
xsi:schemaLocation=”http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd” >
很明显,有关’beans’的声明都放在http://www.springframework.org/schema/beans/spring-beans-3.0.xsd里面了。可能是网络原因,访问不倒导致解析app-config.xml失败,致使程序抛出异常。
打开spring-beans-3.0.1.RELEASE.jar一看,那个xsd文件就在org.springframework.beans.factory.xml包下面,这下子好办了,把xsd文件的引用全改为本地的就行了:
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:context=”http://www.springframework.org/schema/context”
xsi:schemaLocation=”http://www.springframework.org/schema/beans
classpath:/org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
classpath:/org/springframework/context/config/spring-context-3.0.xsd” >
相关推荐
当遇到“cvc-elt.1: 找不到元素 'beans' 的声明”这种异常时,通常意味着Spring在尝试解析XML配置文件时遇到了问题。这个错误提示表明XML解析器无法找到`<beans>`元素的定义,这是一个基本的Spring配置文件结构元素...
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'dubbo:application'. - schema_reference.4: Failed to read schema document '...
电大职业技能实训版计算机网络技术网络管理方向专业网站美工设计基础形成性考核答案.doc
计算机等级考试一级练习题解析.doc
机械设备电气控制(含PLC)(B)答案.doc
利用综合测评板以及若干电阻、电容元件设计制作电路,以产生以下四路信号: 幅度不小于3.2V,频率在19kHz到21kHz范围内连续可调的方波脉冲信号。 与方波脉冲信号同频率的正弦波信号,要求其输出电压失真度不超过5%,峰峰值(VPP)不低于1V。 与方波脉冲信号同频率且占空比在5%到15%之间连续可调的窄脉冲信号,幅度不小于3.2V。 与正弦波信号相交的余弦波信号,相位误差不超过5°,输出电压峰峰值(VPP)不小于1V。 所有信号的输出端均需连接1kΩ负载电阻(RL),并将各路信号输出连接至测评板的指定位置。同时,需在引线处贴上对应输出信号的标签,以便于后续测试。
【目标检测】榴莲叶片病害数据集1410张YOLO-VOC格式.docx
火力发电厂机组级检修项目管理标准分析.doc
自考电子商务法概论模拟试卷.doc
数据集介绍 本数据集旨在根据品牌商家的历史订单数据,构建一个预测模型,预估用户人群在规定时间内产生购买行为的概率。
电子商务管理课程实验指导书.doc
湘潭大学移动通信实验报告实验6GSM及GPRS移动台短消息发送及接收实验.docx
网络规划与组建实训指导.doc
网络服务平台电商服务平台合作协议书.doc
【目标检测】4种铁轨表面缺陷检测数据集4020张YOLO+VOC格式.docx
罗克韦尔自动化能源管理系统概述.docx
【目标检测】空中小目标无人机检测数据集840张YOLO+VOC.docx
计算机信息系统集成资质等级评定条件(修定版).doc
自考计算机应用管理信息系统开发.doc
【目标检测】80种手语检测数据集9648张YOLO+VOC.docx