spring异常之:Document root element "beans", must match DOCTYPE root "null"

遇到一个新问题,ssh项目部署时遇到Document root element "beans", must match DOCTYPE root "null".的错误提示,网上很多人说要把applicationContex.xml文件中加上如下第二行的<!DOCTYPE/>标签,说明DTD,其实并不准确。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
……
</beans>
    后来在spring forum上发现了正解:
You have the wrong xml configuration for the version of spring.

1.x use DOCTYPE
2.x use schema

You must have 1.x in the classpath.
引自http://forum.springframework.org/showthread.php?t=37883

    现在明白了,spring 1.x 使用DOCTYPE,而2.x是用schema,我的项目出错原因是由于前面的其他错误怀疑spring版本问题把spring2.0换成了spring1.2,但applicationContex.xml还是使用
<?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.0.xsd">
    更换spring为2.0问题解决。

猜你喜欢

转载自wangxr66.iteye.com/blog/1541276