hibernate和spring整合问题

kevinxxw 发布于 2015/07/30 15:23
阅读 1K+
收藏 0

整合hibernate和spring的时候,出现了下面的问题,找了好久都不知道哪里出了错,麻烦各位大神看看,小弟感激不尽!

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]

Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider]

Caused by: java.lang.ClassCastException: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider cannot be cast to org.hibernate.engine.jdbc.connections.spi.ConnectionProvider


spring配置文件如下:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test" />
<property name="user" value="root" />
<property name="password" value="root" />
<property name="maxPoolSize" value="20" />
<property name="minPoolSize" value="2" />
<property name="initialPoolSize" value="2" />
<property name="maxIdleTime" value="20" />
</bean>


<!-- 定义Hibernate的SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>hibernateConfig/Login.hbm.xml</value>
</list>
</property>
<!-- 设置Hibernate的相关属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
<!-- 设置Hibernate一个提交批次中的最大SQL语句数 -->
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="show_sql">50</prop>
</props>
</property>
</bean>


<!--定义Hibernate的事务管理器HibernateTransactionManager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- 依赖注入上面定义的sessionFactory -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>






<bean id="firstService" class="com.demo.service.serviceImpl.FirstServiceImpl" />
<bean id="loginAction" class="com.demo.action.LoginAction" scope="prototype">
<property name="fs" ref="firstService" />
</bean>


<bean id="loginDao" class="com.demo.dao.daoImpl.LoginDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="loginService" class="com.demo.service.serviceImpl.LoginServiceImpl">
<property name="loginDao" ref="loginDao" />
</bean>
<bean id="registerAction" class="com.demo.action.RegisterAction"
scope="prototype">
<property name="ls" ref="loginService" />
</bean>

加载中
0
如比如比
kevinxxw
kevinxxw
谢谢,问题已解决,用的是hibernate4的包,且这个版本与spring3的不兼容,换成hibernate3的包就行了
返回顶部
顶部