2008-11-05 205 views
2

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

誰能告訴我什麼,我做錯了什麼?

回答

4

原來,這是因爲我在Spring 1.x中使用了Hibernate 3,這意味着DTD是錯誤的。更新了項目中的Spring JAR文件並解決了問題。

0

您未關閉<beans>標記。將</beans>添加到配置文件的末尾。

+0

的吊牌齊全,我只是忘了,包括它得到了解決。更新了問題 – Elie 2008-11-05 20:56:21

0

看你的堆棧跟蹤:

 
    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-彈簧core.xml文件的錯誤,而不是你在你的帖子包含的春天文件。

+0

有什麼樣的錯誤?因爲該文件的第16行完全相同。 – Elie 2008-11-05 21:00:31

1

您可能使用的是舊版本的spring.jar。我得到這個,當我使用了最新的spring.jar

1

更新您的spring.jar與最新版本