SpringBoot3.4.0無法找到StringRedisTemplate?bean的問題Consider?defining?a?bean?of?type?‘org.springframework
問題描述:
使用StringRedisTemplate 時出現(xiàn)異常
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內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
利用Spring Validation實現(xiàn)輸入驗證功能
這篇文章主要給大家介紹了如何利用Spring Validation完美的實現(xiàn)輸入驗證功能,文中有詳細的代碼示例,具有一定的參考價值,感興趣的朋友可以借鑒一下2023-06-06
基于SpringBoot和Hutool工具包實現(xiàn)驗證碼的案例
隨著安全性的要求越來越高,目前項目中很多都會使用驗證碼,只要涉及到登錄,絕大多數都會有驗證的要求,驗證碼的形式也是多種多樣,更復雜的圖形驗證碼和行為驗證碼已經成為了更流行的趨勢,本文給大家介紹了SpringBoot Hutool實現(xiàn)驗證碼的案例,需要的朋友可以參考下2024-05-05
Spring的FactoryBean<Object>接口示例代碼
FactoryBean是Spring框架中的一個接口,用于創(chuàng)建和管理Bean對象,它的作用是將Bean的創(chuàng)建過程交給FactoryBean實現(xiàn)類來完成,而不是直接由Spring容器來創(chuàng)建,本文給大家介紹Spring的FactoryBean<Object>接口,感興趣的朋友一起看看吧2023-11-11
SpringBoot項目中讀取resource目錄下的文件六種方法
這篇文章給大家總結了SpringBoot項目中讀取resource目錄下的文件六種方法,文中有詳細的代碼示例供大家參考,具有一定的參考價值,需要的朋友可以參考下2024-05-05

