merou
merou

Reputation: 11

Exception using spring3

I have developed an application using Spring 3 and Hibernate. For Testing my DAO I use Junit and when I run the test I get an exception.

This is part of my application 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; nested exception is org.xml.sax.SAXParseException: L'élément racine de document "beans" doit correspondre à la racine DOCTYPE "null". org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 105; L'élément racine de document "beans" doit correspondre à la racine DOCTYPE "null". at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)

Upvotes: 0

Views: 614

Answers (2)

Vikash B
Vikash B

Reputation: 1005

xsi:schemalocation for Spring beans is wrong. Change the first line of xsi:schemalocation to

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

Upvotes: 2

Eugene Ryzhikov
Eugene Ryzhikov

Reputation: 17369

Add </beans> at the end of your context file

Upvotes: 0

Related Questions