2

这是我的 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>

当我运行我的应用程序测试时,这是我得到的错误:

    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 '>'.

我正在使用 Spring 3.0.7

4

3 回答 3

4

试试这个...

<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>
于 2013-08-13T13:46:28.323 回答
1
<?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>
于 2013-08-14T01:46:20.127 回答
0

实际上仍然完全支持 DTD 样式: http: //static.springsource.org/spring/docs/3.0.x/reference/xsd-config.html

支持DTD?

仍然完全支持使用较旧的 DTD 样式编写 Spring 配置文件。

如果您放弃使用新的基于 XML Schema 的方法来创作 >Spring XML 配置文件,一切都不会中断。你失去的只是有机会拥有更多>简洁和清晰的配置。无论 XML 配置是基于 DTD 还是 >Schema,最终都归结为容器中的相同对象模型(即 > 一个或多个 BeanDefinition 实例)。

根据您的问题,这可能是网络问题,您是否尝试直接在浏览器中打开http://www.springframework.org/dtd/spring-beans-2.0.dtd?(我认为您会在您直接在浏览器中打开http://www.springframework.org/dtd/spring-beans-2.0.dtd 。)

于 2013-08-14T02:48:04.917 回答