Spring配置错误

时间:2008-11-05 20:47:49

标签: hibernate spring

我的spring-context文件如下所示。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:jms="http://www.springframework.org/schema/jms"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

    <bean id="cfaBeanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg value="classpath:cfa-spring-core.xml" />
    </bean>
</beans>

当我尝试运行我的应用程序时,出现以下错误:

Caused by: org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:cfa-spring-context.xml], factory key [cfaBeanFactory]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Line 16 in XML document from URL [file:/C:/.../cfa-spring-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
    at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:389)
    ... 56 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Line 16 in XML document from URL [file:/C:/.../cfa-spring-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:169)
    ... 59 more
Caused by: org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)

有人能告诉我我做错了吗?

5 个答案:

答案 0 :(得分:5)

原来这是因为我在Spring 1.x中使用Hibernate 3,这意味着DTD是错误的。更新了项目中的Spring JAR文件并修复了问题。

答案 1 :(得分:1)

您可能正在使用旧版本的spring.jar。我得到了这个,当我使用最新的spring.jar

时它就解决了

答案 2 :(得分:1)

使用最新版本更新spring.jar

答案 3 :(得分:0)

您没有关闭<beans>标记。将</beans>添加到配置文件的末尾。

答案 4 :(得分:0)

查看你的stacktrace:

    Line 16 in XML document from URL [file:/C:/.../cfa-spring-context.xml] is invalid;
    nested exception is org.xml.sax.SAXParseException: Document root element "beans", 
    must match DOCTYPE root "null".

您似乎在 cfa-spring-core.xml 文件中出错,而不是您在帖子中包含的弹出文件。