日期:2014-05-19  浏览次数:20732 次

请教spring3.1和hibernate4整合中的一个问题
我在整合spring3.1和hibernate4的时候发现了一个问题,就是spring去创建sessionFactory的时候,报java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext的错误。具体的错误如下:
Java code
java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:591)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
    at org.unitils.orm.hibernate.util.HibernateSessionFactoryLoader.createSessionFactoryBean(HibernateSessionFactoryLoader.java:63)
    at org.unitils.orm.hibernate.util.HibernateSessionFactoryLoader.getConfiguredOrmPersistenceUnit(HibernateSessionFactoryLoader.java:38)
    at org.unitils.orm.common.OrmModule.getConfiguredPersistenceUnit(OrmModule.java:181)
    at org.unitils.orm.common.OrmModule.getPersistenceUnit(OrmModule.java:136)
    at org.unitils.orm.hibernate.HibernateModule$1.getSpringPlatformTransactionManager(HibernateModule.java:102)
    at org.unitils.database.transaction.impl.DefaultUnitilsTransactionManager.doStartTransaction(DefaultUnitilsTransactionManager.java:117)
    at org.unitils.database.transaction.impl.DefaultUnitilsTransactionManager.activateTransactionIfNeeded(DefaultUnitilsTransactionManager.java:110)
    at org.unitils.database.DatabaseModule.activateTransactionIfNeeded(DatabaseModule.java:234)
    at org.unitils.database.DatabaseModule.getDataSourceAndActivateTransactionIfNeeded(DatabaseModule.java:218)
    at org.unitils.orm.hibernate.util.HibernateSessionFactoryLoader.getDataSource(HibernateSessionFactoryLoader.java:78)
    at org.unitils.orm.hibernate.util.HibernateSessionFactoryLoader.createSessionFactoryBean(HibernateSessionFactoryLoader.java:48)
    at org.unitils.orm.hibernate.util.HibernateSessionFactoryLoader.getConfiguredOrmPersistenceUnit(HibernateSessionFactoryLoader.java:38)
    at org.unitils.orm.common.OrmModule.getConfiguredPersistenceUnit(OrmModule.java:181)
    at org.unitils.orm.common.OrmModule.getPersistenceUnit(OrmModule.java:136)
    at org.unitils.orm.common.OrmModule.injectOrmPersistenceUnitIntoTestObject(OrmModule.java:322)
    at org.unitils.orm.common.OrmModule$OrmTestListener.beforeTestSetUp(OrmModule.java:367)
    at org.unitils.core.Unitils$UnitilsTestListener.beforeTestSetUp(Unitils.java:273)
    at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:151)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java