SpringBoot項(xiàng)目啟動失敗的常見錯誤總結(jié)
一、項(xiàng)目識別與依賴問題
1. 項(xiàng)目不被IDE識別為Maven項(xiàng)目
報錯內(nèi)容:
沒有啟動的三角按鈕 項(xiàng)目結(jié)構(gòu)缺少 Maven Dependencies
原因:IDEA沒有將其識別為一個Maven項(xiàng)目
2. 依賴未下載或下載失敗
報錯內(nèi)容:
Could not resolve dependencies pom.xml 文件出現(xiàn)紅色下劃線
原因:依賴沒有下載到本地或者本地文件殘缺
二、配置文件問題
1. 配置文件編碼錯誤(YAML)
報錯內(nèi)容:
Caused by: org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 2
原因:application.yml文件編碼不是UTF-8
2. 配置文件格式錯誤
報錯內(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)不正確或格式錯誤
三、環(huán)境配置問題
1. JDK版本不匹配
報錯內(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. 端口被占用
報錯內(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注入問題
1. 依賴沖突
報錯內(nèi)容:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isCandidateClass(Ljava/lang/Class;Ljava/lang/Class;)Z
原因:不同依賴之間存在版本沖突
2. Bean找不到
報錯內(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掃描問題
報錯內(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.
原因:啟動類未配置正確的Mapper掃描路徑
五、數(shù)據(jù)庫連接問題
1. 數(shù)據(jù)源配置缺失
報錯內(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ù)庫配置缺失(如spring.datasource.url等)
2. 數(shù)據(jù)庫連接失敗
報錯內(nèi)容:
Unable to connect to database
原因:
- 數(shù)據(jù)庫服務(wù)未啟動
- 數(shù)據(jù)庫用戶名或密碼錯誤
- 數(shù)據(jù)庫URL配置錯誤
六、啟動類問題
1. 啟動類配置錯誤
報錯內(nèi)容:
找不到主類
原因:
- 啟動類未正確標(biāo)注@SpringBootApplication注解
- IDE運(yùn)行配置主類路徑錯誤
- 項(xiàng)目結(jié)構(gòu)不正確
七、其他常見問題
1. 中文亂碼問題
報錯內(nèi)容:
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
原因:編碼格式不一致
2. 依賴版本不匹配
報錯內(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)目啟動失敗的常見錯誤總結(jié)的文章就介紹到這了,更多相關(guān)SpringBoot項(xiàng)目啟動失敗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java微信二次開發(fā)(三) Java微信各類型消息封裝
這篇文章主要為大家詳細(xì)介紹了Java微信二次開發(fā)第三篇,Java微信各類型消息封裝,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04
在SpringBoot中整合使用Netty框架的詳細(xì)教程
這篇文章主要介紹了在SpringBoot中整合使用Netty框架的教程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06
Mysql?json類型字段Java+Mybatis數(shù)據(jù)字典功能的實(shí)踐方式
這篇文章主要介紹了Mysql?json類型字段Java+Mybatis數(shù)據(jù)字典功能的實(shí)踐方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
SpringBoot中的JPA(Java?Persistence?API)詳解
這篇文章主要介紹了SpringBoot中的JPA(Java?Persistence?API)詳解,JPA用于將?Java?對象映射到關(guān)系型數(shù)據(jù)庫中,它提供了一種面向?qū)ο蟮姆绞絹聿僮鲾?shù)據(jù)庫,使得開發(fā)者可以更加方便地進(jìn)行數(shù)據(jù)持久化操作,需要的朋友可以參考下2023-07-07

