1. 程式人生 > 其它 >SSM整合時報錯:java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded

SSM整合時報錯:java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded

今天在SSM整合除錯時報了一個錯誤java.lang.NoClassDefFoundError,部分內容如下:

Mar 27, 2022 2:45:19 PM org.springframework.test.context.support.AbstractTestContextBootstrapper getDefaultTestExecutionListenerClassNames
INFO: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
Mar 27, 2022 2:45:19 PM org.springframework.test.context.support.AbstractTestContextBootstrapper getTestExecutionListeners
INFO: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@20322d26, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@192b07fd, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@64bfbc86, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@64bf3bbf, org.springframework.test.context.support.DirtiesContextTestExecutionListener@55d56113, org.springframework.test.context.transaction.TransactionalTestExecutionListener@148080bb, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@dc24521, org.springframework.test.context.event.EventPublishingTestExecutionListener@10bdf5e5]
Mar 27, 2022 2:45:19 PM org.springframework.test.context.TestContextManager prepareTestInstance
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@64bf3bbf] to prepare test instance [MapperTest@52feb982]
java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded


Caused by: java.lang.ClassNotFoundException: org.springframework.core.ErrorCoded
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 57 more


java.lang.NoClassDefFoundError: org/springframework/core/ErrorCoded


Caused by: java.lang.ClassNotFoundException: org.springframework.core.ErrorCoded
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 57 more

Process finished with exit code -1

找了好久都沒有找到問題出現在哪,最後檢視依賴發現,我在引入spring-test依賴時發現裡面也包含spring-core這個包,兩個spring-core包版本不一致從而引發錯誤

 

 解決方法:

1、把spring-test的版本也更改為4.3.7

 

 2、重新整理maven,這是可以看到兩個spring-core的版本一致了

 

 3、再次進行除錯,執行成功,問題解決