5. 成功解决:Could not autowire. No beans of ‘RedisConnectionFactory‘ type found.

在这里插入图片描述

❤️ 个人主页:水滴技术
🌸 订阅专栏:成功解决 BUG 合集
🚀 支持水滴:点赞👍 + 收藏⭐ + 留言💬

问题描述

今天建了一个新项目,使用 Spring Boot 整合 Redis 时,IDEA 被提醒“Could not autowire. No beans of ‘RedisConnectionFactory’ type found. ”错误,意思是不能自动装配“RedisConnectionFactory”。

虽然有这个错误提醒,但是可以正常使用,很奇怪。

在这里插入图片描述
另外我的 Spring Boot 版本是 2.7.3

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

原因分析

之前的项目一直是这么使用,所以不会是代码的问题。那就只能试下其他的版本。经过排查,确定是 Spring Boot 版本的问题,我试过所有 2.7.* 的版本,都会有这个问题。而降到 2.6.* 版本,就不会有这个提示。

解决方案

将 Spring Boot 版本降到 2.6.11 版本,即可解决。

在这里插入图片描述
2.6.11 是 2.6.* 中最新的 GA 版:

在这里插入图片描述

目前还不知道2.7.* 版本会出现这个问题,后面知晓后会更新答案。

  • 18
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 23
    评论
问题描述中提到了在创建redisTemplate时出现了错误,错误信息是"Could not autowire. No beans of 'RedisConnectionFactory' type found." \[1\] 这个错误通常是由于Spring Boot版本的问题引起的。根据资料,大部分2.x版本的Spring Boot都会出现这个问题,但并不影响正常使用\[2\]。 解决这个问题的方法是在配置类中手动创建RedisConnectionFactory的bean,并将其注入到redisTemplate中。可以参考下面的代码示例: ```java @Bean public RedisConnectionFactory redisConnectionFactory() { // 在这里配置Redis连接工厂的相关信息 // 例如使用Lettuce连接池: RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(); configuration.setHostName("localhost"); configuration.setPort(6379); LettuceConnectionFactory factory = new LettuceConnectionFactory(configuration); return factory; } @Bean public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashValueSerializer(new StringRedisSerializer()); redisTemplate.setConnectionFactory(connectionFactory); return redisTemplate; } ``` 通过手动创建RedisConnectionFactory的bean,并将其注入到redisTemplate中,可以解决"Could not autowire. No beans of 'RedisConnectionFactory' type found."的问题\[3\]。 #### 引用[.reference_title] - *1* [Could not autowire. No beans of ‘RedisConnectionFactorytype found.已解决](https://blog.csdn.net/baiqi123456/article/details/128318413)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Spring Boot 整合redis:Could not autowire. No beans of ‘RedisConnectionFactorytype found.](https://blog.csdn.net/qq_32923975/article/details/130484863)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Could not autowire. No beans of ‘RedisConnectionFactorytype found.](https://blog.csdn.net/qq_67972273/article/details/126388082)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 23
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水滴技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值