简体   繁体   English

使用spring3的例外情况

[英]Exception using spring3

I have developed an application using Spring 3 and Hibernate. 我使用Spring 3和Hibernate开发了一个应用程序。 For Testing my DAO I use Junit and when I run the test I get an exception. 为了测试我的DAO我使用Junit,当我运行测试时,我得到一个例外。

This is part of my application context.xml: 这是我的应用程序context.xml的一部分:

<?xml version="1.0" encoding="UTF-8"?>
<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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost/register"/>
    <property name="username" value="root"/>
</bean>


<bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/> 

    <property name="annotatedClasses">
        <list>
            <value>com.model.Register</value>
        </list>
    </property>


    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hbm2ddl.auto">update</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

When I run my test I get the following exception: 当我运行我的测试时,我得到以下异常:

org.springframework.beans.factory.BeanDefinitionStoreException: Line 10 in XML document from class path resource [application-context.xml] is invalid; org.springframework.beans.factory.BeanDefinitionStoreException:来自类路径资源[application-context.xml]的XML文档中的第10行无效; nested exception is org.xml.sax.SAXParseException: L'élément racine de document "beans" doit correspondre à la racine DOCTYPE "null". 嵌套异常是org.xml.sax.SAXParseException:L'élémentracinede document“beans”doitàlaracine DOCTYPE“null”。 org.xml.sax.SAXParseException; org.xml.sax.SAXParseException; lineNumber: 10; lineNumber:10; columnNumber: 105; columnNumber:105; L'élément racine de document "beans" doit correspondre à la racine DOCTYPE "null". L'élémentracinede document“beans”doit la lacine DOCTYPE“null”。 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

xsi:schemalocation for Spring beans is wrong. xsi:Spring bean的schemalocation是错误的。 Change the first line of xsi:schemalocation to 将xsi:schemalocation的第一行更改为

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

You missed the -3.0.xsd 你错过了-3.0.xsd

在上下文文件的末尾添加</beans>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM