SpringBoot整合Redis啟動失敗的常見錯誤以及解決方法
一、Redis服務(wù)配置問題
1. Redis服務(wù)未啟動
報錯內(nèi)容:
Unable to connect to Redis server: 127.0.0.1/127.0.0.1:6379
原因:Redis服務(wù)未啟動
2. Redis配置文件錯誤(bind和protected-mode)
報錯內(nèi)容:
org.springframework.data.redis.connection.RedisConnectionFailureException: Unable to connect to Redis server: 127.0.0.1/127.0.0.1:6379
原因:
- Redis配置文件中
bind 127.0.0.1未注釋 protected-mode未設(shè)置為no
解決方案:
- 注釋
bind 127.0.0.1行 - 將
protected-mode yes改為protected-mode no
二、配置文件錯誤
1. 連接參數(shù)配置錯誤
報錯內(nèi)容:
Caused by: org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1:6379
原因:
- 配置文件中的host、port或password與實際Redis服務(wù)不匹配
- YAML配置縮進(jìn)錯誤
正確配置:
spring:
redis:
host: 127.0.0.1
port: 6379
password: password
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
max-wait: 1s
三、依賴問題
1. 缺少必要依賴
報錯內(nèi)容:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConnectionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.class]: Cannot create a Redis connection factory for the given configuration.
原因:缺少spring-boot-starter-data-redis依賴
解決方案:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2. 依賴版本不兼容
報錯內(nèi)容:
Caused by: java.lang.NoClassDefFoundError: org.springframework.data.redis.connection.RedisConnectionFactory
原因:Jedis與spring-boot-starter-data-redis版本不兼容
解決方案:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.3.1</version> <!-- 與Spring Boot版本匹配 -->
</dependency>
四、Redis集群配置錯誤
1. 客戶端配置為集群模式,但Redis未開啟集群
報錯內(nèi)容:
ERR This instance has cluster support disabled
原因:
- 配置了
spring.redis.cluster.nodes但Redis未配置為集群模式
解決方案:
- 如果使用單節(jié)點(diǎn),修改為單節(jié)點(diǎn)配置:
spring:
redis:
host: 127.0.0.1
port: 6379
- 如果需要集群,確保Redis已正確配置集群
五、密碼配置問題
1. 密碼不匹配
報錯內(nèi)容:
org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: ERR Client sent AUTH, but no password is set
原因:
- 配置了password但Redis服務(wù)器未設(shè)置密碼
- 配置的password與Redis實際密碼不匹配
解決方案:
- 確保Redis配置文件中設(shè)置了正確的密碼:
requirepass your_password
- 確保配置文件中password與Redis設(shè)置一致
六、網(wǎng)絡(luò)與防火墻問題
1. 防火墻阻止端口訪問
報錯內(nèi)容:
org.springframework.data.redis.connection.RedisConnectionFailureException: Unable to connect to Redis server: 127.0.0.1/127.0.0.1:6379
原因:防火墻阻止了6379端口的訪問
解決方案:
# CentOS firewall-cmd --zone=public --add-port=6379/tcp --permanent firewall-cmd --reload
七、連接池配置問題
1. 連接池參數(shù)配置不當(dāng)
報錯內(nèi)容:
org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to XXX.XXX.XXX:6379
原因:連接池配置不合理,導(dǎo)致連接被耗盡
解決方案:
spring:
redis:
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 0
max-wait: 1s
八、依賴沖突問題
1. 依賴版本沖突
報錯內(nèi)容:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.RepositoryConfigurationSource
原因:依賴版本沖突,特別是Spring Data Commons版本不匹配
解決方案:
- 移除顯式指定的依賴版本,讓Spring Boot自動管理版本
- 確保所有依賴與Spring Boot版本兼容
九、Redis服務(wù)端問題
1. Redis服務(wù)端端口被占用
報錯內(nèi)容:
org.springframework.data.redis.connection.RedisConnectionFailureException: Unable to connect to Redis server: 127.0.0.1/127.0.0.1:6379
原因:6379端口被其他進(jìn)程占用
解決方案:
# 檢查端口占用 netstat -anp | grep 6379 # 結(jié)束占用進(jìn)程 kill -9 <PID>
總結(jié)
- 確認(rèn)Redis服務(wù)已啟動:
redis-cli ping應(yīng)返回PONG - 檢查配置文件:確保host、port、password正確
- 檢查依賴:確保包含
spring-boot-starter-data-redis和Jedis - 檢查Redis配置:注釋bind 127.0.0.1,設(shè)置protected-mode no
- 檢查防火墻:確保6379端口開放
- 檢查連接池配置:合理配置連接池參數(shù)
- 檢查版本兼容性:確保Spring Boot與Redis客戶端版本兼容
以上就是SpringBoot整合Redis啟動失敗的常見錯誤以及解決方法的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot整合Redis啟動失敗的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java FineReport報表工具導(dǎo)出EXCEL的四種方式
這篇文章主要介紹了Java FineReport報表工具導(dǎo)出EXCEL的四種方式的相關(guān)資料,需要的朋友可以參考下2016-03-03
springboot2.1.3 hystrix集成及hystrix-dashboard監(jiān)控詳解
Hystrix是Netflix開源的微服務(wù)容錯工具,通過線程池隔離和熔斷機(jī)制防止服務(wù)崩潰,支持降級、監(jiān)控及流量控制,提升系統(tǒng)穩(wěn)定性和可用性2025-08-08
Java實現(xiàn)簡單學(xué)生信息管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Java實現(xiàn)簡單學(xué)生信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09
Java基礎(chǔ)總結(jié)之Thymeleaf詳解
Thymeleaf是一種現(xiàn)代的基于服務(wù)器端的Java模板引擎技術(shù),也是一個優(yōu)秀的面向Java的XML、XHTML、HTML5頁面模板,它具有豐富的標(biāo)簽語言、函數(shù)和表達(dá)式,在使用Spring Boot框架進(jìn)行頁面設(shè)計時,一般會選擇Thymeleaf模板,需要的朋友可以參考下2021-05-05
springboot訪問template下的html頁面的實現(xiàn)配置
這篇文章主要介紹了springboot訪問template下的html頁面的實現(xiàn)配置,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
詳解JAVA生成將圖片存入數(shù)據(jù)庫的sql語句實現(xiàn)方法
這篇文章主要介紹了詳解JAVA生成將圖片存入數(shù)據(jù)庫的sql語句實現(xiàn)方法的相關(guān)資料,這里就是實現(xiàn)java生成圖片并存入數(shù)據(jù)庫的實例,需要的朋友可以參考下2017-08-08
Spring security基于數(shù)據(jù)庫中賬戶密碼認(rèn)證
這篇文章主要介紹了Spring security基于數(shù)據(jù)庫中賬戶密碼認(rèn)證,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-03-03
springboot如何使用logback-spring配置日志格式,并分環(huán)境配置
這篇文章主要介紹了springboot如何使用logback-spring配置日志格式,并分環(huán)境配置的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-07-07
Windows系統(tǒng)下JDK1.8與JDK11版本切換超詳細(xì)教程
這篇文章主要給大家介紹了關(guān)于Windows系統(tǒng)下JDK1.8與JDK11版本切換的超詳細(xì)教程,我們可以有多個工程項目,用的JDK版本不一樣,這個時候就需要進(jìn)行自由切換JDK版本了,需要的朋友可以參考下2023-07-07

