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)文章
SpringBoot+Redis?BitMap實(shí)現(xiàn)簽到與統(tǒng)計的項(xiàng)目實(shí)踐
最近項(xiàng)目里需要集成簽到和統(tǒng)計功能,連續(xù)簽到后會給用戶發(fā)放一些優(yōu)惠券和獎品,以此來吸引用戶持續(xù)在該品臺進(jìn)行活躍,本文就詳細(xì)的介紹一下如何實(shí)現(xiàn),感興趣的可以了解一下2023-09-09
實(shí)例解析Java設(shè)計模式編程中的適配器模式使用
適配器模式的主要作用是在新接口和老接口之間進(jìn)行適配,通過將一個類的接口轉(zhuǎn)換成客戶期望的另一個接口,讓原本不兼容的接口可以合作無間,本文以實(shí)例解析Java設(shè)計模式編程中的適配器模式使用,需要的朋友可以參考下2016-05-05
Mybatis-Plus批量添加或修改數(shù)據(jù)的3種方式總結(jié)
使用Mybatis-plus可以很方便的實(shí)現(xiàn)批量新增和批量修改,不僅比自己寫foreach遍歷方便很多,而且性能也更加優(yōu)秀,下面這篇文章主要給大家介紹了關(guān)于Mybatis-Plus批量添加或修改數(shù)據(jù)的3種方式,需要的朋友可以參考下2023-05-05
spring cloud學(xué)習(xí)入門之config配置教程
這篇文章主要給大家介紹了關(guān)于spring cloud學(xué)習(xí)入門之config配置的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用spring cloud具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-09-09

