Cannot find the declaration of element 'beans'

http://llyzq.iteye.com/blog/1117288

spring配置文件原来是这样写的: 

Xml代码   收藏代码
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.        xsi:schemaLocation="http://www.springframework.org/schema/beans org/springframework/beans/factory/xml/spring-beans-2.0.xsd"  
  4.              default-lazy-init="true">  


由于应用会有无互联网的环境下运行,同事将命名空间的引用改成了 
org/springframework/beans/factory/xml/spring-beans-2.0.xsd 
但不知道为什么在我本地上运行却不行 

最后google了好几次才找到原因 

Java代码   收藏代码
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.        xsi:schemaLocation="http://www.springframework.org/schema/beans        
  4.        classpath:/org/springframework/beans/factory/xml/spring-beans-2.0.xsd"  
  5.              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” > 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值