NoClassDefFoundError: logging LogFactory解决
的有关信息介绍如下:下午学习hibernate缓存机制的时候遇到了一个这样的异常:java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory。最后排除原因,寻到了解决答案,原因是缓存机制需要ehcache.jar包,同时也需要commons.loggin.jar包,下边详细介绍一下
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.ehcache.CacheManager.
at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:131)
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.start(RegionFactoryCacheProviderBridge.java:72)
at org.hibernate.impl.SessionFactoryImpl.
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at com.gis520.sessionFactory.HibernateSessionFactory.
at com.gis520.test.EmpTest.testSelect(EmpTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
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.apache.commons.logging.LogFactory
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)
... 30 more
出现以上的异常是由于缺少一个commons-logging的jar包,commons-logging.jar包的作用可以说是和Log4j.jar类似,都是对日记处理等。但是工程里边已经有了log4j.jar了还是报这个错,我也纳闷,是一定需要commons-logging.jar包吧。。小编也是初学者,待得知答案再告诉大家。或者大家知道答案的评论一下哦。一起学习。网上下载一个commons-logging。jar包
将包拷贝到工程的lib文件下——》add to build path
添加好后运行程序即可发现解决了异常、
net.sf.ehcache.CacheException异常解决的方法:http://jingyan.baidu.com/article/d45ad1489349ca69552b80c4.html