当前位置: 代码迷 >> J2EE >> 请问spring3.1和hibernate4整合中的一个有关问题
  详细解决方案

请问spring3.1和hibernate4整合中的一个有关问题

热度:5   发布时间:2016-04-22 01:01:29.0
请教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:61)    at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)    at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)    at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)Caused by: java.lang.ClassNotFoundException: org.hibernate.context.CurrentSessionContext    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)    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)    ... 47 more
  相关解决方案