SpringBoot程序啟動報錯:FileNotFoundException:class path resource [***] cannot be opened because it does not exist


SpringBoot項目,啟動程序ApiApplication。好好的一個程序,今天在啟動程序時發現報錯。

Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.emax.channel.webapp.ApiApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/apache/ibatis/plugin/Interceptor.class] cannot be opened because it does not exist

這是個老生常談的錯誤,既然是org/apache/ibatis/plugin/Interceptor.class,就是缺少apache相關jar包(或其他定義了package為org.apache.ibatis.plugin的jar包)依賴。

執行mvn:clean install了一下,發現並無卵用,問題依然存在。
同樣的程序,同事電腦上可以正常啟動。
那看來還是跟本地jar包依賴有關。然后,沿着這個思路,把相關jar重新install一下。發現還是沒解決。
我開始把焦點放在異常堆棧上,試圖從stacktrace尋找一些線索,卻也吃了閉門羹,沒發現什么有價值的東西。

 

2022-03-01 20:08:09.116[START] [ac75dfedd2c343548a40d8e02291fd3b] [main] INFO o.a.d.s.b.c.e.AwaitingNonWebApplicationListener:162 - [Dubbo] Current Spring Boot Application is about to shutdown...
2022-03-01 20:08:09.136[START] [ac75dfedd2c343548a40d8e02291fd3b] [main] ERROR org.springframework.boot.SpringApplication:858 - Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.emax.channel.webapp.ApiApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/apache/ibatis/plugin/Interceptor.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.emax.channel.webapp.ApiApplication.main(ApiApplication.java:32)
Caused by: java.io.FileNotFoundException: class path resource [org/apache/ibatis/plugin/Interceptor.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:88)
at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:75)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:81)
at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:685)
at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getInterfaces(ConfigurationClassParser.java:1011)
at org.springframework.context.annotation.ConfigurationClassParser.processInterfaces(ConfigurationClassParser.java:375)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:323)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:191)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:295)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
... 13 common frames omitted

Process finished with exit code 1


我就把異常message里提到的 Interceptor ,去相關依賴工程里去查找。 不經意發現,自己曾經在本地測試時,添加了一個實現了Interceptor的MybatisInterceptor類。 罪魁禍首就是這個MybatisInterceptor,把它去掉就好了。不禁又想起了郭德綱於謙早年的相聲《羊上樹》。。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM