当我尝试测试 spring 和 hibernate 集成时,出现以下异常。
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 18 more
应用程序上下文
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<!-- Datasource beans -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/sterlingschema" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<!-- Hibernate Template session factory bean -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/org/droidaceapps/domain/users.hbm.xml</value>
</list>
</property>
</bean>
<!-- Hibernate template beans -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- DAO beans -->
<bean id="userDAO" class="org.droidaceapps.dao.UserDAOImpl">
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<!-- Service beans -->
<bean id="userService" class="org.droidaceapps.services.UserServiceImpl">
<property name="userDAO" ref="userDAO" />
</bean>
当我用谷歌搜索这个问题时,有人说我们应该使用 springframework.orm.hibernate4 而不是 springframework.orm.hibernate3。我这样做了。但我仍然得到同样的例外。
有人可以帮助我确定我在这里缺少什么。
谢谢