Kaloyan Roussev
Kaloyan Roussev

Reputation: 14711

Spring Framework: The document type declaration for root element type "beans" must end with '>'

This is my spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "http://www.springframework.org/dtd/spring-beans-2.0.dtd" PUBLIC "-//SPRING//DTD BEAN 2.0//EN">
<beans>
    <bean id="data" class="com.blah.tests.DataProviderClass" />
    <bean id="wdcm" class="com.blah.tests.WebDriverCustomMethods"/>
</beans>

When I run my application test, this is the error I get:

    Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
 Line 2 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException;
 lineNumber: 2; columnNumber: 82; The document type declaration for root element type "beans" must end with '>'.

Im using Spring 3.0.7

Upvotes: 2

Views: 6362

Answers (3)

user2550754
user2550754

Reputation: 905

Try this...

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" >  

     <bean id="data" class="com.blah.tests.DataProviderClass" />
     <bean id="wdcm" class="com.blah.tests.WebDriverCustomMethods"/>

</beans>

Upvotes: 4

Liping Huang
Liping Huang

Reputation: 4476

Actually the DTD style is still fully supported: http://static.springsource.org/spring/docs/3.0.x/reference/xsd-config.html

DTD support?

Authoring Spring configuration files using the older DTD style is still fully supported.

Nothing will break if you forego the use of the new XML Schema-based approach to authoring >Spring XML configuration files. All that you lose out on is the opportunity to have more >succinct and clearer configuration. Regardless of whether the XML configuration is DTD- or >Schema-based, in the end it all boils down to the same object model in the container (namely >one or more BeanDefinition instances).

according to your issue, this is maybe caused by the network, did you try to open http://www.springframework.org/dtd/spring-beans-2.0.dtd directly in the browser?(I think you will get error when you open http://www.springframework.org/dtd/spring-beans-2.0.dtd directly in the browser.)

Upvotes: 0

lyrl
lyrl

Reputation: 122

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<!-- <bean/> definitions here -->

</beans>

Upvotes: 1

Related Questions