java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > SpringBoot3.4.0无法找到StringRedisTemplate bean

SpringBoot3.4.0无法找到StringRedisTemplate bean的问题Consider defining a bean of type ‘org.springframework

作者:码喽Plus

本文主要介绍了SpringBoot3.4.0无法找到StringRedisTemplate bean的问题Consider defining a bean of type ‘org.springframework,具有一定的参考价值,感兴趣的可以了解一下

问题描述:

使用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 { ... }

到此这篇关于SpringBoot3.4.0无法找到StringRedisTemplate bean的问题Consider defining a bean of type ‘org.springframework的文章就介绍到这了,更多相关SpringBoot3.4.0无法找到StringRedisTemplate bean内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

您可能感兴趣的文章:
阅读全文