问题描述
这是什么错误呀?请高手帮忙解决org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userManager'definedinclasspathresource[applicationContext-beans.xml]:Cannotresolvereferencetobean'sessionFactory'whilesettingbeanproperty'sessionFactory';nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[applicationContext-common.xml]:Initializationofbeanfailed;nestedexceptionisjava.lang.NoClassDefFoundError:org/hibernate/cache/CacheProvideratorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)atcom.gwy.usermanager.manager.UserManagerImplTest.testAddUser(UserManagerImplTest.java:17)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atjunit.framework.TestCase.runTest(TestCase.java:168)atjunit.framework.TestCase.runBare(TestCase.java:134)atjunit.framework.TestResult$1.protect(TestResult.java:110)atjunit.framework.TestResult.runProtected(TestResult.java:128)atjunit.framework.TestResult.run(TestResult.java:113)atjunit.framework.TestCase.run(TestCase.java:124)atjunit.framework.TestSuite.runTest(TestSuite.java:243)atjunit.framework.TestSuite.run(TestSuite.java:238)atorg.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)atorg.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[applicationContext-common.xml]:Initializationofbeanfailed;nestedexceptionisjava.lang.NoClassDefFoundError:org/hibernate/cache/CacheProvideratorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)atorg.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)...37moreCausedby:java.lang.NoClassDefFoundError:org/hibernate/cache/CacheProvideratjava.lang.Class.getDeclaredMethods0(NativeMethod)atjava.lang.Class.privateGetDeclaredMethods(Class.java:2427)atjava.lang.Class.getDeclaredMethods(Class.java:1791)atjava.beans.Introspector$1.run(Introspector.java:1272)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1270)atjava.beans.Introspector.getTargetMethodInfo(Introspector.java:1136)atjava.beans.Introspector.getBeanInfo(Introspector.java:387)atjava.beans.Introspector.getBeanInfo(Introspector.java:159)atorg.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:220)atorg.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:144)atorg.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:252)atorg.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:259)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1132)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:992)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)...46moreCausedby:java.lang.ClassNotFoundException:org.hibernate.cache.CacheProvideratjava.net.URLClassLoader$1.run(URLClassLoader.java:200)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:188)atjava.lang.ClassLoader.loadClass(ClassLoader.java:307)atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)atjava.lang.ClassLoader.loadClass(ClassLoader.java:252)atjava.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)...62more
解决方案
解决方案二:
java.lang.NoClassDefFoundError:org/hibernate/cache/CacheProvider应该是jar包冲突问题,检查一下有没有重复的jar包,删除低版本,保留高版本,顺便确定下有没有少jar。
解决方案三:
试过了,不行呀
解决方案四:
'userManager在context-bean.xml中的定义错误,估计你有引用属性没有设定吧