2012-11-16 33 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