views:

3093

answers:

5

My spring-context file is shown below.

<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"&gt;

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

When I try to run my application, I get the following error:

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)

Can someone tell me what I'm doing wrong?

A: 

you are not closing the <beans> tag. Add </beans> to the end of your config file.

Mike Pone
the tag is complete, I just forgot to include. Updated the question
Elie
A: 

Looking at your 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".

You appear to have an error in the cfa-spring-core.xml file, rather than the spring file you included in your posting.

toolkit
what kind of error? Because line 16 of that file is exactly the same.
Elie
+3  A: 

Turns out this is because I'm using Hibernate 3 with Spring 1.x which means the DTDs are wrong. Updated the Spring JAR file in the project and that fixed the problem.

Elie
+1  A: 

You may be using old version of spring.jar. I got this and it got solved when I used the latest spring.jar

Simion
A: 

Update your spring.jar with latest version

joy