Spring: Document root element "beans", must match DOCTYPE root "null

 今天在项目中出现“Document root element "beans", must match DOCTYPE root "null”, 原来运行好好的代码,为什么这种问题呢? 根据提示,貌似是dtd或者schema的问题, 也确实是它的问题,但是分析过程却是这样的。

 问题分析过程:

 思考1、自己新加入了什么依赖呢? 加了如下的依赖:

  1. <dependency> 
  2.       <groupId>com.alibaba.external</groupId> 
  3.       <artifactId>sourceforge.spring.aop</artifactId> 
  4.       <version>2.0.7</version> 
  5.     </dependency> 

是2.0版本以上的版本啊,这能有什么问题?

思考2:是不是spring配置文件的格式出现了问题呢?

  拷贝了原来运行良好的文件头部进行替换,加上了“<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">”,但是问题依然没有解决。 替换的头部如下:

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 

或者

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2.  
  3. <beans xmlns="http://www.springframework.org/schema/beans" 
  4.             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  5.             xmlns:aop="http://www.springframework.org/schema/aop" 
  6.             xmlns:tx="http://www.springframework.org/schema/tx" 
  7.             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
  8.                      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
  9.                      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> 

思考3:spring的依赖问题

在思考1中提到是使用的2.0.7版本,仔细查看依赖关系之后发现,该版本使用了sourceforge.spring的依赖。真是晕倒, 也不知道是同事在加入仓库的时候搞错了还是spring自身的依赖的时候版本搞错了。

分析好原因之后则做及时调试依赖

 

后来在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,

posted @ 2011-07-25 07:54  上善¤若水  阅读(155)  评论(0编辑  收藏  举报