2014-02-23 85 views
1

當我嘗試運行我的項目時出現以下錯誤。我檢查了我得到這個類,但我不明白爲什麼它仍然會給出這個錯誤。越來越找不到類[org.springframework.orm.hibernate4.LocalSessionFactoryBean]

SEVERE: Context initialization failed 
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 

我的pom.xml

.... 
<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>4.0.1.RELEASE</version> 
    </dependency> 

appcontext.xml

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource"/> 
    <property name="packagesToScan"> 
     <list> 
      <value>entities</value> 
     </list> 
    </property> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
      <prop key="hibernate.show_sql">true</prop> 
     </props> 
    </property> 
</bean> 

回答

0

大的機會,它是因爲不同版本的春天在您的項目被加載。將以下內容添加到您的pom.xml中:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-framework-bom</artifactId> 
      <version>4.0.0.RELEASE</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement>