Consider defining a bean of type 'org.springframework.data.redis.core.HashOperations' 的解决

在Spring Boot应用中集成Redis时遇到自动配置不足的问题,启动时提示需明确定义'org.springframework.data.redis.core.HashOperations'的bean。通过手动注册RedisTemplate并注意在分布式环境中保持序列化一致性来解决此问题。StringRedisTemplate虽方便存储字符串,但操作相同Key可能相互影响,避免混用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在spring boot整合redis时,本以为springboot已经实现了对redis的完美结合。只需要一个@Autowired就可以使用RedisTemplate模板了,结果项目启动出现了下面的惊喜。。。

很明显让我们指明RedisTemplate在项目中的配置。果然,好记性不如烂笔头,突然想起来在之前的项目中已经使用过redis,其中就有这部分内容,但自己负责的不是这个模块而已,很是尴尬。。。

所以我找到RedisTemplate注册bean.

package com.dsx.redis.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/***
 * 
* @ClassName: RedisConfig  
* @Description: redis配置类
* @author 曰业而安  
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值