1、啟動報錯信息。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-08-26 13:55:08.454 ERROR 5600 --- [main] [TID: N/A] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'operateLogApiImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'operateLogServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminUserService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'permissionServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'deptServiceImpl': Bean with name 'deptServiceImpl' has been injected into other beans [deptServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:332)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
at cn.iocoder.yudao.module.system.SystemServerApplication.main(SystemServerApplication.java:25)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'operateLogServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminUserService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'permissionServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'deptServiceImpl': Bean with name 'deptServiceImpl' has been injected into other beans [deptServiceImpl] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.
2023-08-26 13:55:08.390 INFO 5600 --- [main] [TID: N/A] com.alibaba.druid.pool.DruidDataSource : {dataSource-2} closing ...
2023-08-26 13:55:08.394 INFO 5600 --- [main] [TID: N/A] com.alibaba.druid.pool.DruidDataSource : {dataSource-2} closed
2023-08-26 13:55:08.394 INFO 5600 --- [main] [TID: N/A] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closing ...
2023-08-26 13:55:08.395 INFO 5600 --- [main] [TID: N/A] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed
2023-08-26 13:55:08.395 INFO 5600 --- [main] [TID: N/A] c.b.d.d.DynamicRoutingDataSource : dynamic-datasource all closed success,bye
2023-08-26 13:55:08.397 INFO 5600 --- [main] [TID: N/A] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-08-26 13:55:08.418 INFO 5600 --- [main] [TID: N/A] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-08-26 13:55:08.454 ERROR 5600 --- [main] [TID: N/A] o.s.boot.SpringApplication : Application run failed
2、項目環(huán)境與bug說明
- 項目有一個微服務(wù)功能合并到另一個微服務(wù)里面去了,然后把這個微服務(wù)刪除了,主pom里面對應(yīng)的內(nèi)容也刪除了
- 項目是用的芋道微服務(wù)架構(gòu),項目有公共模塊,具體的業(yè)務(wù)微服務(wù)都會在pom文件中引用公共模塊。
- 項目之前項目啟動都是正常的,所以在啟動類上添加 掃描包路徑也是沒用的,因為已經(jīng)在依賴?yán)锩嫣砑恿斯材K的依賴。
3、bug處理過程
- 首先在代碼的報錯地方進(jìn)行 debug,通過 evaluation 里面執(zhí)行 SpringUtil.getApplicationContext().getBean("缺少的bean"),得到的結(jié)果就是null,說明公共依賴?yán)锏腷ean還沒有創(chuàng)建。
- 網(wǎng)上很多說要在啟動類上加 @ComponentScan(basePackages = {"xxx.xxx"}),我試了沒用,因為pom里面引用了,把公共模塊所謂子模塊引用就能獲取到對應(yīng)的bean了。
- 然后聯(lián)想到我只是把某一個子模塊刪除了,然后出現(xiàn)的這個問題,應(yīng)該是maven依賴的問題,它可能直接去本地倉庫去找公共模塊了,然后去本地倉庫一看,果然有對應(yīng)的 artifactId;我就把本地倉庫有關(guān)的依賴都給刪除了。
- 刪除了啟動還是報錯,這就奇怪了,它應(yīng)該沒問題了啊,而且我已經(jīng)重啟過 idea,清理過緩存了,但是執(zhí)行 maven clean 報錯了,顯示從倉庫里找不到 公共依賴,我都刪除了呀,怎么還去倉庫里面找了??????
-
最后的解決方法是 把 父 pom 里面的所有微服務(wù)注釋掉,刷新maven,這時候各個微服務(wù)都沒有父項目,然后再把注釋打開,再刷新maven,然后啟動就 ok 了。
image.png
4、總結(jié)
這個bug困擾了我半天,最開始就懷疑是緩存的問題,我甚至都重啟電腦了,還是啟動報錯,而且在 它的報錯內(nèi)容里面有很多 error create bean XXX ,然后看了很多無用的博客,啟動了幾個微服務(wù)報的錯都不一樣,每個服務(wù)報錯的源頭都是引用的 公用依賴的 bean 是null。所以就是公用模塊的依賴問題了。
對于原來項目啟動沒問題,改動pom文件導(dǎo)致的項目啟動失敗,大概率都是maven本地倉庫的緩存,或者就是項目里面的緩存。
