代码之家  ›  专栏  ›  技术社区  ›  Elie

弹簧配置错误

  •  3
  • Elie  · 技术社区  · 16 年前

    我的Spring上下文文件如下所示。

    <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 回复  |  直到 14 年前
        1
  •  5
  •   Elie    16 年前

    结果发现这是因为我在Spring1.x中使用了Hibernate3,这意味着DTD是错误的。更新了项目中的SpringJAR文件,解决了这个问题。

        2
  •  1
  •   Simion    14 年前

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

        3
  •  1
  •   joy    14 年前

    用最新版本更新spring.jar

        4
  •  0
  •   Mike Pone    16 年前

    你没有关闭 <beans> 标签。添加 </beans> 到配置文件的结尾。

        5
  •  0
  •   toolkit    16 年前

    查看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文件 文件,而不是包含在您的日志中的Spring文件。