java - Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactory] for bean with name 'sessionFactory' -
i created project in spring using maven dependencies getting above mentioned error. changed version of hibernate dependency stil nt resolved here code:
pom.xml
<?xml version="1.0" encoding="utf-8"?> <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/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.shr</groupid> <artifactid>apps</artifactid> <name>springjdbcproject</name> <packaging>war</packaging> <version>1.0.0-build-snapshot</version> <properties> <java-version>1.6</java-version> <org.springframework-version>3.1.1.release</org.springframework-version> <org.aspectj-version>1.6.10</org.aspectj-version> <org.slf4j-version>1.6.6</org.slf4j-version> </properties> <dependencies> <!-- spring --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>${org.springframework-version}</version> <exclusions> <!-- exclude commons logging in favor of slf4j --> <exclusion> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${org.springframework-version}</version> </dependency> <!-- mysql database driver --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.9</version> </dependency> <!--hibernate --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>3.6.10.final</version> </dependency> <!--jdbc --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> <version>${org.springframework-version}</version> </dependency> <!-- aspectj --> <dependency> <groupid>org.aspectj</groupid> <artifactid>aspectjrt</artifactid> <version>${org.aspectj-version}</version> </dependency> <!-- logging --> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <version>${org.slf4j-version}</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>jcl-over-slf4j</artifactid> <version>${org.slf4j-version}</version> <scope>runtime</scope> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>${org.slf4j-version}</version> <scope>runtime</scope> </dependency> <dependency> <groupid>log4j</groupid> <artifactid>log4j</artifactid> <version>1.2.15</version> <exclusions> <exclusion> <groupid>javax.mail</groupid> <artifactid>mail</artifactid> </exclusion> <exclusion> <groupid>javax.jms</groupid> <artifactid>jms</artifactid> </exclusion> <exclusion> <groupid>com.sun.jdmk</groupid> <artifactid>jmxtools</artifactid> </exclusion> <exclusion> <groupid>com.sun.jmx</groupid> <artifactid>jmxri</artifactid> </exclusion> </exclusions> <scope>runtime</scope> </dependency> <!-- @inject --> <dependency> <groupid>javax.inject</groupid> <artifactid>javax.inject</artifactid> <version>1</version> </dependency> <!-- servlet --> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>jsp-api</artifactid> <version>2.1</version> <scope>provided</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> </project>
servlet-context.xml
<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <beans:bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <beans:property name="driverclassname" value="com.mysql.jdbc.driver" /> <beans:property name="url" value="jdbc:mysql://localhost:3306/customerdb" /> <beans:property name="username" value="root" /> <beans:property name="password" value="root" /> </beans:bean> <beans:bean id="sessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactory"> <beans:property name="datasource" ref="datasource" /> <beans:property name="packagestoscan" value="com.shr.customer.model" /> <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</beans:prop> </beans:props> </beans:property> </beans:bean> </beans:beans>
exception:
info : org.springframework.context.support.classpathxmlapplicationcontext - refreshing org.springframework.context.support.classpathxmlapplicationcontext@a981ca: startup date [thu may 09 00:47:37 ist 2013]; root of context hierarchy info : org.springframework.beans.factory.xml.xmlbeandefinitionreader - loading xml bean definitions class path resource [spring.xml] info : org.springframework.beans.factory.support.defaultlistablebeanfactory - pre-instantiating singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@e45076: defining beans [datasource,sessionfactory]; root of factory hierarchy exception in thread "main" org.springframework.beans.factory.cannotloadbeanclassexception: cannot find class [org.springframework.orm.hibernate3.annotation.annotationsessionfactory] bean name 'sessionfactory' defined in class path resource [spring.xml]; nested exception java.lang.classnotfoundexception: org.springframework.orm.hibernate3.annotation.annotationsessionfactory @ org.springframework.beans.factory.support.abstractbeanfactory.resolvebeanclass(abstractbeanfactory.java:1262) @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.predictbeantype(abstractautowirecapablebeanfactory.java:576) @ org.springframework.beans.factory.support.abstractbeanfactory.isfactorybean(abstractbeanfactory.java:1331) @ org.springframework.beans.factory.support.abstractbeanfactory.isfactorybean(abstractbeanfactory.java:897) @ org.springframework.beans.factory.support.defaultlistablebeanfactory.preinstantiatesingletons(defaultlistablebeanfactory.java:566) @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:913) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:464) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:83) @ com.shr.common.app.main(app.java:17) info : org.springframework.beans.factory.support.defaultlistablebeanfactory - destroying singletons in org.springframework.beans.factory.support.defaultlistablebeanfactory@e45076: defining beans [datasource,sessionfactory]; root of factory hierarchy caused by: java.lang.classnotfoundexception: org.springframework.orm.hibernate3.annotation.annotationsessionfactory @ java.net.urlclassloader$1.run(urlclassloader.java:200) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:188) @ java.lang.classloader.loadclass(classloader.java:306) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:276) @ java.lang.classloader.loadclass(classloader.java:251) @ org.springframework.util.classutils.forname(classutils.java:258) @ org.springframework.beans.factory.support.abstractbeandefinition.resolvebeanclass(abstractbeandefinition.java:417) @ org.springframework.beans.factory.support.abstractbeanfactory.doresolvebeanclass(abstractbeanfactory.java:1283) @ org.springframework.beans.factory.support.abstractbeanfactory.resolvebeanclass(abstractbeanfactory.java:1254) ... 9 more
i believe missing spring-orm
dependency.
<dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>3.1.1.release</version> </dependency>
that contains spring-hibernate(3|4) classes. (replace 3.1.1.release
whichever version intend use.)
Comments
Post a Comment