问题描述:
使用StringRedisTemplate 时出现异常
Consider defining a bean of type 'org.springframework.data.redis.core.StringRedisTemplate' in your configuration.
问题分析:
(1)查看pom文件中是否引入相关依赖(这里我使用的是springboot3.4.0的版本)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- 显式指定 Lettuce 版本 -->
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>6.2.4.RELEASE</version> <!-- 匹配 Spring Boot 3.4.0 的推荐版本 -->
</dependency>
(2)Redis 配置缺失(springboot3如下,springboot2将data去掉)
spring:
data:
redis:
host: localhost
port: 6379
(3)检查自动配置
排除自动配置类:检查 @SpringBootApplication 或 @EnableAutoConfiguration 是否排除了 RedisAutoConfiguration
// 错误示例:排除了 Redis 自动配置
@SpringBootApplication(exclude = {RedisAutoConfiguration.class})
public class MyApplication { ... }


发布评论