spring boot 3.x 中 spring.redis.xxx 配置前缀已废弃,必须全部迁移至 spring.data.redis.xxx;包括 host、port、password、timeout(需带单位)、lettuce.pool.max-size 等,且仅支持 lettuce 客户端。

spring.redis.xxx 配置在 Spring Boot 3.x 中直接失效
不是配置写错了,而是整个前缀被废弃了。spring.redis.host、spring.redis.port、spring.redis.database 这类写法在 Spring Boot 3.x 启动时会报 Deprecated configuration property 警告,且连接根本不会建立——因为 Spring Boot 3.x 的 RedisProperties 类已完全移除该层级。
- Spring Boot 2.x 用的是
org.springframework.boot.autoconfigure.redis.RedisProperties,支持spring.redis.* - Spring Boot 3.x 改为
org.springframework.boot.autoconfigure.data.redis.RedisProperties,只认spring.data.redis.* - IDE(如 IntelliJ)可能仍提示自动补全
spring.redis,那是缓存或旧插件残留,不可信
必须把 redis 配置移到 spring.data.redis 下
迁移不是加个 data 就完事,整个路径要重写,包括连接池、超时、客户端类型等所有子项。漏掉任意一层,都可能导致参数未生效或 fallback 到默认值(比如 max-size: 8 而非你期望的 20)。
Redis 缓存和数据结构管理技能。通过自然语言操作 Redis,支持 String、Hash、List、Set、ZSet、Stream 等数据结构操作。当用户提到 Redis、缓存、消息队列、会话存储时使用此技能。
-
spring.redis.timeout→spring.data.redis.timeout(注意单位:3.0+ 默认要求带单位,如3000ms) -
spring.redis.lettuce.pool.max-active→spring.data.redis.lettuce.pool.max-size(max-active已废弃) -
spring.redis.password→spring.data.redis.password(空密码也要显式写password: "",否则可能被忽略) - 如果用了
@ConfigurationProperties(prefix = "spring.redis")自定义配置类,必须同步改成"spring.data.redis"
Lettuce 是唯一支持的客户端,Jedis 不再可用
Spring Boot 3.x 彻底移除了 Jedis 的 auto-configuration 和 starter 依赖。即使你手动引入 jedis jar,spring.data.redis.client-type=jedis 也会触发启动失败,报错类似:Failed to bind properties under 'spring.data.redis.client-type'。
- 所有连接池配置必须走
spring.data.redis.lettuce.pool.*,没有jedis分支 -
lettuce.pool.enabled: true在 3.2+ 是默认开启的,但显式声明更稳妥,避免某些 profile 下被意外关闭 - 若项目原来重度依赖 Jedis 的阻塞 API(比如
Jedis.eval直接调用),需改用 Lettuce 的RedisClient+StatefulRedisConnection或RedisTemplate.execute()
容易被忽略的兼容性细节
最常被跳过的不是主配置路径,而是 timeout、database、connect-timeout 这几个看似“次要”的字段。它们在 3.x 中有隐式行为变化:
-
spring.data.redis.database必须是整数(不能是字符串"0"),否则解析失败 -
connect-timeout和timeout是两个独立字段:前者控制 TCP 握手,后者控制命令执行;3.x 默认不设connect-timeout,网络波动时可能卡住初始化 - SSL 配置从
spring.redis.ssl=true变为spring.data.redis.ssl.enabled=true,且需要额外引入io.lettuce:lettuce-core6.3+ - 如果你用
RedisTemplate并自定义了RedisConnectionFactoryBean,检查是否还硬编码了new RedisStandaloneConfiguration(...)—— 它的构造参数顺序在 Lettuce 6.3+ 有调整










