【问题标题】:Spring configuration error弹簧配置错误
【发布时间】:2010-09-20 23:07:53
【问题描述】:

我的 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)

谁能告诉我我做错了什么?

【问题讨论】:

    标签: hibernate spring


    【解决方案1】:

    用最新版本更新你的 spring.jar

    【讨论】:

      【解决方案2】:

      您可能使用的是旧版本的 spring.jar。我得到了这个,当我使用最新的spring.jar时它得到了解决

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          【解决方案4】:

          查看您的堆栈跟踪:

          来自 URL [file:/C:/.../cfa-spring-context.xml] 的 XML 文档中的第 16 行无效; 嵌套异常是 org.xml.sax.SAXParseException: Document root element "beans", 必须匹配 DOCTYPE 根“null”。

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

          【讨论】:

          • 什么样的错误?因为该文件的第 16 行完全相同。
          【解决方案5】:

          您没有关闭&lt;beans&gt; 标记。将&lt;/beans&gt; 添加到配置文件的末尾。

          【讨论】:

          • 标签是完整的,我只是忘了包括。更新了问题
          猜你喜欢
          • 2012-07-05
          • 1970-01-01
          • 2011-09-11
          • 2019-09-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多