SpringBoot項(xiàng)目報(bào)錯(cuò):"Error?starting?ApplicationContext...."解決辦法
發(fā)現(xiàn)錯(cuò)誤
SpringBoot項(xiàng)目報(bào)錯(cuò):
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
以下方案80%可以幫助您解決這些個(gè)‘可惡的’問題
報(bào)錯(cuò)內(nèi)容和截圖如下:
Connected to the target VM, address: '127.0.0.1:4963', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.10.RELEASE)
2021-12-25 14:52:41.578 INFO 13204 --- [ main] m.c.DiitMicrosoftserviceCheckApplication : Starting DiitMicrosoftserviceCheckApplication on 老云的計(jì)算機(jī) with PID 13204 (D:\svn\workspace_nxzrbhdzt\Gh_yizhangtu\dit-check\target\classes started by liuyundashen in D:\svn\workspace_nxzrbhdzt\Gh_yizhangtu\dit-check)
2021-12-25 14:52:41.583 INFO 13204 --- [ main] m.c.DiitMicrosoftserviceCheckApplication : No active profile set, falling back to default profiles: default
2021-12-25 14:52:43.485 INFO 13204 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-12-25 14:52:43.503 INFO 13204 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-12-25 14:52:43.504 INFO 13204 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-12-25 14:52:43.668 INFO 13204 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-12-25 14:52:43.668 INFO 13204 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1979 ms
2021-12-25 14:52:43.832 INFO 13204 --- [ main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource
2021-12-25 14:52:43.910 ERROR 13204 --- [ main] com.alibaba.druid.pool.DruidDataSource : testWhileIdle is true, validationQuery not set
2021-12-25 14:52:43.917 INFO 13204 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
_ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\
/ |
3.2.0
2021-12-25 14:52:44.365 WARN 13204 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cheakRecordController': Unsatisfied dependency expressed through field 'recordService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TRecordServiceImpl': Unsatisfied dependency expressed through field 'packageService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resultPackageBaseinfoServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'importDB.datasource.url' in value "${importDB.datasource.url}"
2021-12-25 14:52:44.366 INFO 13204 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closing ...
2021-12-25 14:52:44.368 INFO 13204 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed
2021-12-25 14:52:44.372 INFO 13204 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-12-25 14:52:44.391 INFO 13204 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-25 14:52:44.410 ERROR 13204 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cheakRecordController': Unsatisfied dependency expressed through field 'recordService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TRecordServiceImpl': Unsatisfied dependency expressed through field 'packageService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resultPackageBaseinfoServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'importDB.datasource.url' in value "${importDB.datasource.url}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.14.RELEASE.jar:5.2.14.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.10.RELEASE.jar:2.3.10.RELEASE]

——在看到這些個(gè)問題的時(shí)候,日志基本都會(huì)告訴你錯(cuò)誤的地方,所以我們大部分可以根據(jù)日志報(bào)錯(cuò)的信息分析錯(cuò)誤的原因:
一、編譯出問題
仔細(xì)看報(bào)出的問題,有沒有如:“Description:…” 這樣的字眼,沒有 “描述”,如上圖所示,這種情況下的操作:
1.clean清理一下; 2.然后install重新編譯一下 ;

3.也可以用這個(gè)命令,重新編譯一下

這個(gè)時(shí)候重新啟動(dòng),如果還是報(bào)同樣的錯(cuò)誤,打開如下圖位置,看是否有編譯的文件,如mapper.xml文件,application.yml或者application.properties文件,以及一些配置文件等

——哎!生氣,這里發(fā)現(xiàn)真的沒有mapper和配置文件,只有main下面的.jar文件,該怎么辦呢?
——pom.xml文件中給加入要編譯的文件位置依賴,如下:(這是我的文件位置,你根據(jù)你的進(jìn)行調(diào)整)
<!--引入本地資源-->
<resources>
<!--加載lib文件,特殊情況下會(huì)有l(wèi)ib,但大部分都靠依賴下載了-->
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<!--打jar包-->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<!--將properties和xml文件編譯-->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
好的,清理——>打包——>啟動(dòng)——>運(yùn)行成功,搞定收工
二、請(qǐng)求接口重復(fù)
根據(jù)日志看出它說路徑問題;這樣想你寫的接口名字是否重復(fù),只有一個(gè)斜杠或者沒斜杠的情況

如下截圖:

修改如下:

好的,重新啟動(dòng),搞定收工
三、加@Mapper注解
這些情況就是看描述的問題
如圖:

這種情況,看是不是沒有掃描到它需要的東西,給加上@Mapper注解(是掃描dao層的),或者 加上@Service注解(掃描service層)即可。
四、加@SpringBootApplication注解,數(shù)據(jù)庫(kù)問題
根據(jù)問題看出:springboot啟動(dòng)時(shí)會(huì)自動(dòng)注入數(shù)據(jù)源和配置jpa ,解決:
在@SpringBootApplication中排除其注入
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

五、端口重復(fù)問題
查看是否自己的運(yùn)行端口沖突,將其kill殺死,重新啟動(dòng),或者跟換端口
以下是查看端口沖突的方式:
window鍵+R,輸入“netstat -aon|findstr 8080”找到占用8080端口的進(jìn)程號(hào):

2.輸入“tasklist|findstr “3412” ”:
查看進(jìn)程號(hào)為“3412”的進(jìn)程:

3.輸入“taskkill /f /t /im QQ.exe”:(/f:強(qiáng)制性的結(jié)束進(jìn)程)
結(jié)束這個(gè)進(jìn)程

現(xiàn)在可以重新啟動(dòng)一下,看是否運(yùn)行成功
六、包沖突
還有的情況可能是包沖突了,可以將maven倉(cāng)庫(kù)清理一下自己的包,重新下載一下

總結(jié)
到此這篇關(guān)于SpringBoot項(xiàng)目報(bào)錯(cuò):"Error starting ApplicationContext...."解決辦法的文章就介紹到這了,更多相關(guān)SpringBoot項(xiàng)目報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springboot集成nacos報(bào)錯(cuò):get data from Nacos error,dataId:null.yaml的原因及解決方法
- Springboot初始化啟動(dòng)報(bào)錯(cuò)Error?creating?bean?with?name?'dataSource'?defined?in?class?path?resource
- SpringBoot啟動(dòng)異常Exception in thread “main“ java.lang.UnsupportedClassVersionError
- SpringBoot項(xiàng)目網(wǎng)頁(yè)加載出現(xiàn)Whitelabel?Error?Page的解決
- Springboot新建項(xiàng)目Spring Initializr Error問題及解決
相關(guān)文章
Java 基礎(chǔ)語(yǔ)法讓你弄懂類和對(duì)象
C 語(yǔ)言是面向過程的,而 Java 是面向?qū)ο笫俏覀兂B牭降囊痪湓?,這章將帶你揭曉Java 基礎(chǔ)語(yǔ)法中類與對(duì)象到底是什么,需要的朋友請(qǐng)參考下文2021-08-08
Java 并發(fā)編程學(xué)習(xí)筆記之Synchronized底層優(yōu)化
這篇文章主要介紹了Java 并發(fā)編程學(xué)習(xí)筆記之Synchronized底層優(yōu)化的相關(guān)資料,主要包含了重量級(jí)鎖,輕量級(jí)鎖,偏向鎖和其他優(yōu)化等方面,有需要的小伙伴可以參考下2016-05-05
JAVA實(shí)現(xiàn)監(jiān)測(cè)tomcat是否宕機(jī)及控制重啟的方法
這篇文章主要介紹了JAVA實(shí)現(xiàn)監(jiān)測(cè)tomcat是否宕機(jī)及控制重啟的方法,可實(shí)現(xiàn)有效的檢測(cè)及控制tomcat服務(wù)器運(yùn)行,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
使用idea的database模塊繪制數(shù)據(jù)庫(kù)er圖的方法
這篇文章主要介紹了使用idea的database模塊繪制數(shù)據(jù)庫(kù)er圖,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-07-07
mybatis判斷int是否為空的時(shí)候,需要注意的3點(diǎn)
這篇文章主要介紹了mybatis判斷int是否為空的時(shí)候,需要注意的3點(diǎn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07

