簡體   English   中英

java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap

[英]java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap

在問這個問題之前,我搜索過stackoverflow,但沒有得到很好的答案。

Spring + Hibernate + Tomcat 依賴問題

當我調試方法時:

在此處輸入圖片說明

我的問題日志如下:

log4j:WARN No appenders could be found for logger (org.hibernate.type.BasicTypeRegistry).
log4j:WARN Please initialize the log4j system properly.

java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap

   at org.hibernate.util.SimpleMRUCache.init(SimpleMRUCache.java:71)
    at org.hibernate.util.SimpleMRUCache.<init>(SimpleMRUCache.java:55)
    at org.hibernate.engine.query.QueryPlanCache.<init>(QueryPlanCache.java:76)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:237)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
    at com.ypd.a.entity.App.testHello(App.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:289)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:114)
    at org.junit.jupiter.engine.descriptor.MethodTestDescriptor.lambda$invokeTestMethod$7(MethodTestDescriptor.java:212)
    at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
    at org.junit.jupiter.engine.descriptor.MethodTestDescriptor.invokeTestMethod(MethodTestDescriptor.java:208)
    at org.junit.jupiter.engine.descriptor.MethodTestDescriptor.execute(MethodTestDescriptor.java:155)
    at org.junit.jupiter.engine.descriptor.MethodTestDescriptor.execute(MethodTestDescriptor.java:63)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$0(HierarchicalTestExecutor.java:80)
    at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$0(HierarchicalTestExecutor.java:87)
    at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$0(HierarchicalTestExecutor.java:87)
    at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:76)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:51)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:129)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:85)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:59)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.map.LRUMap
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 34 more

原因是:

java.lang.ClassNotFoundException: org.apache.commons.collections.map.LRUMap

您的日志中有明顯的解釋:

java.lang.ClassNotFoundException:

如果看到這種類型的錯誤,應該考慮是不是沒有插件庫。

你應該做的是去http://mvnrepository.com搜索commons-collections ,然后復制你想要的版本,添加到你的 pom.xml 中,然后安裝它。

所以過去幾天我一直在處理這個問題。 我仍然在使用 Tomcat 9 時遇到問題,但在 tomcat 8 上我能夠通過將 deps 添加到 commons-collections 和 commons-collections4 來解決這個錯誤,如下所示:

 compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.0' compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'

然后我只是在代碼庫中用 org.apache.commons.collections4 替換了包 org.apache.commons.collections 的所有使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM