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

 更新时间:2025年11月18日 09:21:29   作者:程序员1970  
本文详细介绍了Spring Boot整合Redis启动失败的常见错误及其解决方法,涵盖了服务配置、配置文件、依赖、集群配置、密码、网络、连接池、依赖冲突和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启动失败的资料请关注脚本之家其它相关文章!

相关文章

  • Java FineReport报表工具导出EXCEL的四种方式

    Java FineReport报表工具导出EXCEL的四种方式

    这篇文章主要介绍了Java FineReport报表工具导出EXCEL的四种方式的相关资料,需要的朋友可以参考下
    2016-03-03
  • springboot2.1.3 hystrix集成及hystrix-dashboard监控详解

    springboot2.1.3 hystrix集成及hystrix-dashboard监控详解

    Hystrix是Netflix开源的微服务容错工具,通过线程池隔离和熔断机制防止服务崩溃,支持降级、监控及流量控制,提升系统稳定性和可用性
    2025-08-08
  • Java实现简单学生信息管理系统

    Java实现简单学生信息管理系统

    这篇文章主要为大家详细介绍了Java实现简单学生信息管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-09-09
  • Java基础总结之Thymeleaf详解

    Java基础总结之Thymeleaf详解

    Thymeleaf是一种现代的基于服务器端的Java模板引擎技术,也是一个优秀的面向Java的XML、XHTML、HTML5页面模板,它具有丰富的标签语言、函数和表达式,在使用Spring Boot框架进行页面设计时,一般会选择Thymeleaf模板,需要的朋友可以参考下
    2021-05-05
  • springboot访问template下的html页面的实现配置

    springboot访问template下的html页面的实现配置

    这篇文章主要介绍了springboot访问template下的html页面的实现配置,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-12-12
  • Spring Boot读取配置文件的五种方式小结

    Spring Boot读取配置文件的五种方式小结

    Spring Boot 提供了灵活多样的方式来读取配置文件,这篇文章为大家介绍了5种常见的读取方式,文中的示例代码简洁易懂,大家可以根据自己的需要进行选择
    2025-04-04
  • 详解JAVA生成将图片存入数据库的sql语句实现方法

    详解JAVA生成将图片存入数据库的sql语句实现方法

    这篇文章主要介绍了详解JAVA生成将图片存入数据库的sql语句实现方法的相关资料,这里就是实现java生成图片并存入数据库的实例,需要的朋友可以参考下
    2017-08-08
  • Spring security基于数据库中账户密码认证

    Spring security基于数据库中账户密码认证

    这篇文章主要介绍了Spring security基于数据库中账户密码认证,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-03-03
  • springboot如何使用logback-spring配置日志格式,并分环境配置

    springboot如何使用logback-spring配置日志格式,并分环境配置

    这篇文章主要介绍了springboot如何使用logback-spring配置日志格式,并分环境配置的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-07-07
  • Windows系统下JDK1.8与JDK11版本切换超详细教程

    Windows系统下JDK1.8与JDK11版本切换超详细教程

    这篇文章主要给大家介绍了关于Windows系统下JDK1.8与JDK11版本切换的超详细教程,我们可以有多个工程项目,用的JDK版本不一样,这个时候就需要进行自由切换JDK版本了,需要的朋友可以参考下
    2023-07-07

最新评论