SpringBoot項(xiàng)目啟動(dòng)失敗的常見(jiàn)錯(cuò)誤總結(jié)
一、項(xiàng)目識(shí)別與依賴問(wèn)題
1. 項(xiàng)目不被IDE識(shí)別為Maven項(xiàng)目
報(bào)錯(cuò)內(nèi)容:
沒(méi)有啟動(dòng)的三角按鈕 項(xiàng)目結(jié)構(gòu)缺少 Maven Dependencies
原因:IDEA沒(méi)有將其識(shí)別為一個(gè)Maven項(xiàng)目
2. 依賴未下載或下載失敗
報(bào)錯(cuò)內(nèi)容:
Could not resolve dependencies pom.xml 文件出現(xiàn)紅色下劃線
原因:依賴沒(méi)有下載到本地或者本地文件殘缺
二、配置文件問(wèn)題
1. 配置文件編碼錯(cuò)誤(YAML)
報(bào)錯(cuò)內(nèi)容:
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 2
原因:application.yml文件編碼不是UTF-8
2. 配置文件格式錯(cuò)誤
報(bào)錯(cuò)內(nèi)容:
Failed to load application context
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' defined in null: Could not resolve placeholder 'spring.application.name' in value "${spring.application.name}"
原因:YAML文件縮進(jìn)不正確或格式錯(cuò)誤
三、環(huán)境配置問(wèn)題
1. JDK版本不匹配
報(bào)錯(cuò)內(nèi)容:
Error: A JNI error has occurred, please check your installation and try again Invalid maximum heap size: -Xmx512m The specified size exceeds the maximum representable size.
原因:使用的JDK版本與Spring Boot版本不匹配
- Spring Boot 3.x默認(rèn)要求JDK 17+
- 17以下版本不支持
2. 端口被占用
報(bào)錯(cuò)內(nèi)容:
*************************** APPLICATION FAILED TO START *************************** Description: The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured. Action: Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.
原因:8080端口被其他進(jìn)程占用
四、依賴與Bean注入問(wèn)題
1. 依賴沖突
報(bào)錯(cuò)內(nèi)容:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isCandidateClass(Ljava/lang/Class;Ljava/lang/Class;)Z
原因:不同依賴之間存在版本沖突
2. Bean找不到
報(bào)錯(cuò)內(nèi)容:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.demo.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate.
原因:
- 未添加@Component、@Service等注解
- 掃描路徑不正確
3. Mapper掃描問(wèn)題
報(bào)錯(cuò)內(nèi)容:
Field clustersDetailsAmqMapper in com.ruoyi.clusters.service.impl.ClustersDetailsAmqServiceImpl required a bean of type 'com.ruoyi.clusters.mapper.ClustersDetailsAmqMapper' that could not be found.
原因:?jiǎn)?dòng)類未配置正確的Mapper掃描路徑
五、數(shù)據(jù)庫(kù)連接問(wèn)題
1. 數(shù)據(jù)源配置缺失
報(bào)錯(cuò)內(nèi)容:
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
原因:數(shù)據(jù)庫(kù)配置缺失(如spring.datasource.url等)
2. 數(shù)據(jù)庫(kù)連接失敗
報(bào)錯(cuò)內(nèi)容:
Unable to connect to database
原因:
- 數(shù)據(jù)庫(kù)服務(wù)未啟動(dòng)
- 數(shù)據(jù)庫(kù)用戶名或密碼錯(cuò)誤
- 數(shù)據(jù)庫(kù)URL配置錯(cuò)誤
六、啟動(dòng)類問(wèn)題
1. 啟動(dòng)類配置錯(cuò)誤
報(bào)錯(cuò)內(nèi)容:
找不到主類
原因:
- 啟動(dòng)類未正確標(biāo)注@SpringBootApplication注解
- IDE運(yùn)行配置主類路徑錯(cuò)誤
- 項(xiàng)目結(jié)構(gòu)不正確
七、其他常見(jiàn)問(wèn)題
1. 中文亂碼問(wèn)題
報(bào)錯(cuò)內(nèi)容:
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
原因:編碼格式不一致
2. 依賴版本不匹配
報(bào)錯(cuò)內(nèi)容:
The following dependencies have a problem: - spring-boot-starter-web: 2.4.3 - spring-cloud-starter-eureka: 2.2.12
原因:Spring Boot與Eureka等依賴版本不匹配
到此這篇關(guān)于SpringBoot項(xiàng)目啟動(dòng)失敗的常見(jiàn)錯(cuò)誤總結(jié)的文章就介紹到這了,更多相關(guān)SpringBoot項(xiàng)目啟動(dòng)失敗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java實(shí)現(xiàn)網(wǎng)頁(yè)解析示例
這篇文章主要介紹了java實(shí)現(xiàn)網(wǎng)頁(yè)解析示例,需要的朋友可以參考下2014-04-04
Java微信二次開(kāi)發(fā)(三) Java微信各類型消息封裝
這篇文章主要為大家詳細(xì)介紹了Java微信二次開(kāi)發(fā)第三篇,Java微信各類型消息封裝,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
在SpringBoot中整合使用Netty框架的詳細(xì)教程
這篇文章主要介紹了在SpringBoot中整合使用Netty框架的教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06
使用jdbcTemplate查詢返回自定義對(duì)象集合代碼示例
這篇文章主要介紹了使用jdbcTemplate查詢返回自定義對(duì)象集合代碼示例,分享了相關(guān)代碼示例,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-02-02
Mysql?json類型字段Java+Mybatis數(shù)據(jù)字典功能的實(shí)踐方式
這篇文章主要介紹了Mysql?json類型字段Java+Mybatis數(shù)據(jù)字典功能的實(shí)踐方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
SpringBoot中的JPA(Java?Persistence?API)詳解
這篇文章主要介紹了SpringBoot中的JPA(Java?Persistence?API)詳解,JPA用于將?Java?對(duì)象映射到關(guān)系型數(shù)據(jù)庫(kù)中,它提供了一種面向?qū)ο蟮姆绞絹?lái)操作數(shù)據(jù)庫(kù),使得開(kāi)發(fā)者可以更加方便地進(jìn)行數(shù)據(jù)持久化操作,需要的朋友可以參考下2023-07-07

