当前位置: 代码网 > it编程>编程语言>Java > SpringBoot整合Redis启动失败的常见错误以及解决方法

SpringBoot整合Redis启动失败的常见错误以及解决方法

2025年11月18日 Java 我要评论
一、redis服务配置问题1. redis服务未启动报错内容:unable to connect to redis server: 127.0.0.1/127.0.0.1:6379原因:redis服务

一、redis服务配置问题

1. redis服务未启动

报错内容

unable to connect to redis server: 127.0.0.1/127.0.0.1:6379

原因:redis服务未启动

2. redis配置文件错误(bind和protected-mode)

报错内容

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未设置为no

解决方案

  1. 注释bind 127.0.0.1
  2. protected-mode yes改为protected-mode no

二、配置文件错误

1. 连接参数配置错误

报错内容

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服务不匹配
  • yaml配置缩进错误

正确配置

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. 缺少必要依赖

报错内容

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. 依赖版本不兼容

报错内容

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未开启集群

报错内容

err this instance has cluster support disabled

原因

  • 配置了spring.redis.cluster.nodes但redis未配置为集群模式

解决方案

  1. 如果使用单节点,修改为单节点配置:
spring:
  redis:
    host: 127.0.0.1
    port: 6379
  1. 如果需要集群,确保redis已正确配置集群

五、密码配置问题

1. 密码不匹配

报错内容

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服务器未设置密码
  • 配置的password与redis实际密码不匹配

解决方案

  1. 确保redis配置文件中设置了正确的密码:
requirepass your_password
  1. 确保配置文件中password与redis设置一致

六、网络与防火墙问题

1. 防火墙阻止端口访问

报错内容

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. 连接池参数配置不当

报错内容

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

原因:连接池配置不合理,导致连接被耗尽

解决方案

spring:
  redis:
    lettuce:
      pool:
        max-active: 8
        max-idle: 8
        min-idle: 0
        max-wait: 1s

八、依赖冲突问题

1. 依赖版本冲突

报错内容

correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.repositoryconfigurationsource

原因:依赖版本冲突,特别是spring data commons版本不匹配

解决方案

  1. 移除显式指定的依赖版本,让spring boot自动管理版本
  2. 确保所有依赖与spring boot版本兼容

九、redis服务端问题

1. redis服务端端口被占用

报错内容

org.springframework.data.redis.connection.redisconnectionfailureexception: 
unable to connect to redis server: 127.0.0.1/127.0.0.1:6379

原因:6379端口被其他进程占用

解决方案

# 检查端口占用
netstat -anp | grep 6379

# 结束占用进程
kill -9 <pid>

总结

  1. 确认redis服务已启动redis-cli ping应返回pong
  2. 检查配置文件:确保host、port、password正确
  3. 检查依赖:确保包含spring-boot-starter-data-redis和jedis
  4. 检查redis配置:注释bind 127.0.0.1,设置protected-mode no
  5. 检查防火墙:确保6379端口开放
  6. 检查连接池配置:合理配置连接池参数
  7. 检查版本兼容性:确保spring boot与redis客户端版本兼容

以上就是springboot整合redis启动失败的常见错误以及解决方法的详细内容,更多关于springboot整合redis启动失败的资料请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com