admin管理员组文章数量:1130349
问题描述:
使用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 { ... }
问题描述:
使用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 { ... }
本文标签: StringRedisTemplateSpringBeanorgspringframework
版权声明:本文标题:Spring Boot3.4.0无法找到StringRedisTemplate bean的问题Consider defining a bean of type ‘org.springframework 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754346224a2675213.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论