2012-11-16 30 views
0

我想在我的Spring應用程序中使用Hibernate,但我已經有了項目的部署錯誤休眠BeanCreationException

Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'configurationClass'; nested exception is java.lang.IllegalArgumentException: Cannot find class [org.hibernate.cfg.AnnotationConfiguration]. 

這裏我的調度員的servlet與會話bean工廠:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" 
    default-autowire="byName"> 

<context:component-scan base-package="hibernateTest" /> 

<context:annotation-config/> 

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> 

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" 
     p:suffix=".jsp" /> 

<bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="locations"> 
     <list> 
      <value>classpath:jdbc.properties</value> 
     </list> 
    </property> 
</bean> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation"> 
      <value>classpath:hibernate.cfg.xml</value> 
     </property> 
     <property name="configurationClass"> 
      <value>org.hibernate.cfg.AnnotationConfiguration</value> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
       <prop key="hibernate.show_sql">true</prop> 
      </props> 
     </property> 
</bean> 

<bean id="transactionManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 

我的休眠-cfg.xml中:

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD//EN" 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 
<session-factory> 
    <mapping class="hibernateTest.web.InventoryController" /> 
</session-factory>  
</hibernate-configuration> 

我在我的課程路徑中有很多罐子,我不會錯過任何人。你能幫我找到一個問題嗎?

感謝

回答

1

您需要將hibernate-annotations.jar放在類路徑中。

+0

是的,它缺少抱歉,並感謝您 – tvirgil

+1

@ user1826886 OK,那麼你應該接受和/或給予好評我的回答 –

+0

做過:)感謝。 – tvirgil

0

找不到類[org.hibernate.cfg.AnnotationConfiguration]

這是什麼原因,你可以檢查這個類的類路徑。

0

org.hibernate.cfg.AnnotationConfiguration已被棄用,

和它的所有功能已經轉移到org.hibernate.cfg.Configuration

更改代碼

 <property name="configurationClass"> 
      <value>org.hibernate.cfg.Configuration</value> 
     </property> 
+0

好的,那麼如果我使用它,我仍然可以使用註釋? – tvirgil

+0

如果我把這個值我得到了以下錯誤:創建名爲'sessionFactory'在ServletContext資源中定義的bean時出錯[/WEB-INF/dispatcher-servlet.xml]:調用init方法失敗;嵌套異常是org.hibernate.MappingException:需要AnnotationConfiguration實例來使用 tvirgil