备忘Document root element "beans",must match DOCTYPE root "null"

原因在网上一搜一大堆,比如这篇
http://seenow.blog.hexun.com/19253270_d.html。

转帖如下:


遇到一个新问题,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问题解决。



==============转帖完毕========我是华丽的分割线============================



在使用maven的过程中如果引入了非常多的依赖导致即使找到了spring1.x的包也不知道是哪个依赖引进来的,这个时候有个小技巧:

1、点开“Maven Dependencies”
2、找出spring1.x的包
3、点击右键 --> MAVEN --> Exclude Maven artifact --> 点OK --> done

通过以上三步,可以很轻松的让Maven自动帮你去掉相应依赖中spring1.x的引入。如下所示:

		<dependency>
			<groupId>xbean</groupId>
			<artifactId>xbean-spring</artifactId>
			<version>2.1</version>
			<exclusions>
				<exclusion>
					<artifactId>spring</artifactId>
					<groupId>org.springframework</groupId>
				</exclusion>
			</exclusions>
		</dependency>




猜你喜欢

转载自surlymo.iteye.com/blog/1592562