Spring配置文件xsi:schemaLocation无法解析导致启动失败的解决方案 转!classpath:/org/springframework/

来源:互联网 发布:amuse事务所 知乎 编辑:程序博客网 时间:2024/05/16 01:09
Spring配置文件xsi:schemaLocation无法解析导致启动失败的解决方案本文转自:http://www.jnan.org/archives/2010/12/cannot-find-the-declaration-of-element-beans.html今天向服务器部署一个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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://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/beansclasspath:/org/springframework/beans/factory/xml/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contextclasspath:/org/springframework/context/config/spring-context-3.0.xsd” >

0 0
原创粉丝点击