spring配置文件,出错会报“nested exception is org.xml.sax.SAXParseException: cvc-elt.1:找不到元素“beans”的声明。”,
原因:
因为引用的spring的jar包文件版本不同导致的。
解决办法:
两个不同版本的spring配置文件的头格式如下两种,如果你已经是其中一种,则改成另一种即可。
第一种:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
......
第二种:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
本文详细解析了Spring配置文件中常见的“找不到元素“beans”的声明”错误,指出这是由于使用了不同版本的Spring jar包导致的DTD或Schema不匹配。文章提供了两种不同版本的配置文件头格式,并指导如何根据使用的Spring版本进行相应的修改。
1383

被折叠的 条评论
为什么被折叠?



