文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"

昨天在测试spring的配置文件spring.xml时,Junit测试老是报错,其中主要错误信息为: 
Caused by: java.util.InvalidPropertiesFormatException: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 80;   文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"。

 检查了好多遍spring.xml头部的配置信息,觉得没问题啊,为了确保正确,于是去另外一个正确配置的项目中直接拷贝了头部配置,但是问题依旧存在!

 

在网上搜了好多解决方案,都说是没有结束标签、标签包裹错误、格式错误什么的,搞了一个晚上,内心是极度崩溃的!!后来无意中看到 “重复配置了同一个bean配置文件”的字眼,此时恍然大悟,于是回去把引入的配置文件注释掉

重新进行JUnit测试,问题解决。至此,终于明白其错误是<beans></beans>配置重复引起的。此类问题就像是在引用外部脚本JS文件时,在外部脚本文件中,只能包含脚本语言代码,不能包含<script>标签。

针对于上面spring.xml配置出错解决方案其实很简单,只需要把

    <context:property-placeholder location="classpath:spring-redis.xml" />
    <context:property-placeholder location="classpath:spring-shiro.xml" />
    <context:property-placeholder location="classpath:mongo-config.xml"/>

改成<import resource="classpath:spring-redis.xml" />
       <import resource="classpath:spring-shiro.xml" />
       <import resource="classpath:mongo-config.xml" />

即可,说到底还是自己太年轻了,竟不知道<context:property-placeholder>标签与 <import>标签的区别

猜你喜欢

转载自blog.csdn.net/weixin_37778823/article/details/82077772