java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
Asked Answered
A

3

10

I'm new to Spring this is my first example (JSF 2, PrimeFaces 3, Spring & Hibernate Integration) here's the pom.xml :

<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>MVNO.ONP.project</groupId>
<artifactId>MVNOONPProject</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MVNOONPProject Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.6.SEC03</version>
</dependency>
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>2.1.0-b03</version>
</dependency>
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>2.1.0-b03</version>
</dependency>
 <dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>
 <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.9.Final</version>
 </dependency>

 <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.22</version>
 </dependency>
 </dependencies>
 <build>
  <finalName>MVNOONPProject</finalName>
 </build>
 </project>

when I run the project i get this error :

Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate4.LocalSessionFactoryBean] for bean with name 'SessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1141)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1105)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:386)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    ... 41 more
Caused by: java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
    at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:385)
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
    ... 51 more
Agony answered 27/1, 2013 at 14:44 Comment(0)
W
13

Hibernate 4 support was added to Spring Framework in 3.1.

Your pom.xml references Spring Framework 2.5.6 hence org.springframework.orm.hibernate4.LocalSessionFactoryBean does not exist. You need to update your pom.xml to reference Spring Framework 3.1 or later.

Waitress answered 27/1, 2013 at 14:56 Comment(0)
I
18

Thanks to Mark While I am doing the same problem

  1. Sometimes eclipse will add spring 2.5 jar from local/.m2 Delete it from build path, or even you add spring 4.1, it will still use spring 2.5

2 You should have spring orm dependency in you Maven-dependency add this to pom.xml

 <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-orm</artifactId>
   <version>4.1.6.RELEASE</version>
</dependency>
Ingraft answered 11/5, 2015 at 21:51 Comment(0)
W
13

Hibernate 4 support was added to Spring Framework in 3.1.

Your pom.xml references Spring Framework 2.5.6 hence org.springframework.orm.hibernate4.LocalSessionFactoryBean does not exist. You need to update your pom.xml to reference Spring Framework 3.1 or later.

Waitress answered 27/1, 2013 at 14:56 Comment(0)
A
8

Here's the new pom.xml containing spring 3.1.1:

  <!-- Spring 3 dependencies -->
  <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
   <version>${spring.version}</version>
</dependency>

  <dependency>
  <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
  </dependency> 

 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
   <version>${spring.version}</version>
  </dependency>

 <dependency>
  <groupId>org.springframework</groupId>
   <artifactId>spring-tx</artifactId>
    <version>${spring.version}</version>
   </dependency>

 <dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
 <version>${spring.version}</version>
 </dependency>

  <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
    </dependency>
Agony answered 27/1, 2013 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.