Thursday, 15 May 2014

java - Simple DAO using Hibernate and Spring Framework, don't work: Unable to locate Spring NamespaceHandler for XML schema namespace -



java - Simple DAO using Hibernate and Spring Framework, don't work: Unable to locate Spring NamespaceHandler for XML schema namespace -

i quite new in spring world. trying create spring project work dao next tutorial , using maven:

http://singgihpraditya.wordpress.com/2010/02/13/spring-3-0-and-hibernate-tutorial-part-1/

i have created project in illustration (changing property file access database)

this pom.xml file (created myself because not showed in example)

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>org.andrea.myexample</groupid> <artifactid>myhibernateexample</artifactid> <version>0.0.1-snapshot</version> <packaging>jar</packaging> <name>myhibernateexample</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>3.2.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>3.2.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>3.2.1.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context-support</artifactid> <version>3.2.1.release</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.23</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-hibernate</artifactid> <version>1.2.9</version> </dependency> <dependency> <groupid>javax.persistence</groupid> <artifactid>persistence-api</artifactid> <version>1.0-rev-1</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-annotations</artifactid> <version>3.5.6-final</version> </dependency> <dependency> <groupid>c3p0</groupid> <artifactid>c3p0</artifactid> <version>0.9.0.4</version> </dependency> </dependencies>

to test application not using junit (as in example) have created mainapp* class containing main method, one:

package org.andrea.myexample.myhibernateexample.test; import org.andrea.myexample.myhibernateexample.dao.userdao; import org.andrea.myexample.myhibernateexample.entity.user; import org.springframework.beans.factory.annotation.autowired; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class mainapp { /** * @param args */ public static void main(string[] args) { /* * crea il contesto in base of operations alle impostazioni dell'applicazione definite * nel file beans.xml */ applicationcontext context = new classpathxmlapplicationcontext( "app-config.xml"); /* * recupera united nations bean avente id="texteditor" nel file di configurazione * beans.xml */ userdao dao = (userdao) context.getbean("userdao"); int expectedresult = 1; user user = new user(); user.setage(23); user.setusername("adit"); user.setregistered(true); dao.saveuser(user); } }

in class simply:

obtain "userdao" object context (i think can because, can see in illustration link, userdao class annoted using ** @repository("userdao")** annotation

create new valorized user object , insert in database using dao object.

the problem whene seek run mainapp class, obtain next error in stacktrace:

** info: loading xml bean definitions class path resource [db-config.xml] exception in thread "main" org.springframework.beans.factory.parsing.beandefinitionparsingexception: configuration problem: failed import bean definitions relative location [db-config.xml] offending resource: class path resource [app-config.xml]; nested exception org.springframework.beans.factory.parsing.beandefinitionparsingexception: configuration problem: unable locate spring namespacehandler xml schema namespace [http://www.springframework.org/schema/tx] offending resource: class path resource [db-config.xml] @ org.springframework.beans.factory.parsing.failfastproblemreporter.error(failfastproblemreporter.java:68) @ org.springframework.beans.factory.parsing.readercontext.error(readercontext.java:85) @ org.springframework.beans.factory.parsing.readercontext.error(readercontext.java:76) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.importbeandefinitionresource(defaultbeandefinitiondocumentreader.java:271) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.parsedefaultelement(defaultbeandefinitiondocumentreader.java:196) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.parsebeandefinitions(defaultbeandefinitiondocumentreader.java:181) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.doregisterbeandefinitions(defaultbeandefinitiondocumentreader.java:140) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.registerbeandefinitions(defaultbeandefinitiondocumentreader.java:111) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.registerbeandefinitions(xmlbeandefinitionreader.java:493) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.doloadbeandefinitions(xmlbeandefinitionreader.java:390) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:334) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:302) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:174) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:209) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:180) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:243) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:127) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:93) @ org.springframework.context.support.abstractrefreshableapplicationcontext.refreshbeanfactory(abstractrefreshableapplicationcontext.java:130) @ org.springframework.context.support.abstractapplicationcontext.obtainfreshbeanfactory(abstractapplicationcontext.java:537) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:451) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:83) @ org.andrea.myexample.myhibernateexample.test.mainapp.main(mainapp.java:20) caused by: org.springframework.beans.factory.parsing.beandefinitionparsingexception: configuration problem: unable locate spring namespacehandler xml schema namespace [http://www.springframework.org/schema/tx] offending resource: class path resource [db-config.xml] @ org.springframework.beans.factory.parsing.failfastproblemreporter.error(failfastproblemreporter.java:68) @ org.springframework.beans.factory.parsing.readercontext.error(readercontext.java:85) @ org.springframework.beans.factory.parsing.readercontext.error(readercontext.java:80) @ org.springframework.beans.factory.xml.beandefinitionparserdelegate.error(beandefinitionparserdelegate.java:318) @ org.springframework.beans.factory.xml.beandefinitionparserdelegate.parsecustomelement(beandefinitionparserdelegate.java:1435) @ org.springframework.beans.factory.xml.beandefinitionparserdelegate.parsecustomelement(beandefinitionparserdelegate.java:1428) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.parsebeandefinitions(defaultbeandefinitiondocumentreader.java:184) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.doregisterbeandefinitions(defaultbeandefinitiondocumentreader.java:140) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.registerbeandefinitions(defaultbeandefinitiondocumentreader.java:111) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.registerbeandefinitions(xmlbeandefinitionreader.java:493) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.doloadbeandefinitions(xmlbeandefinitionreader.java:390) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:334) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:302) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.importbeandefinitionresource(defaultbeandefinitiondocumentreader.java:255) ... 20 more **

why? have thought it? how can seek resolve?

thanks

andrea

java spring hibernate spring-mvc dao

No comments:

Post a Comment