springBoot 自动装配reddis Could not autowire. No beans of ‘RedisConnectionFactory‘ type found.

最近写了一个redis的starter服务,将redis配置单独的做成了一个微服务jar包。但是在写完配置之后,出现了Could not autowire. No beans of ‘RedisConnectionFactory’ type found.问题

package com.moyu.book.framework.redis.config;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author moyu
 * @version 1.0
 * @date 2025/7/7 14:22
 */
@AutoConfiguration
public class RedisTemplateConfig {

    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(connectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
        redisTemplate.setValueSerializer(serializer);
        redisTemplate.setHashValueSerializer(serializer);
        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }
}

这个是我的配置类代码,报错截图如下
在这里插入图片描述

首先,启动是正常的,也能正常注入,并且我只行test方法测试,也是成功的
但是缓存到redis库中的数据,确实变成如图
在这里插入图片描述
我明明写的是中文,但是变成了转义符

后经过排查,是因为resource下的spring自动配置需要写上全路径,我忘记写了(尴尬)

但也可能是其他方面原因

可能性最大的,是版本问题,springboot2.7前后可能会有这样的问题,如果不是装配的问题,可以考虑将springboot版本往回退一点试试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值