[已解决]Error creating bean with name ‘redisTemplate‘ defined in class path resource [org/也就是注入bean失败了

在springboot项目中添加了redis的配置类

@Configuration
public class RedisConfig extends CachingConfigurerSupport {

    @Bean
    @Resource
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {

        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
        //默认的Key序列化器为:JdkSerializationRedisSerializer
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setConnectionFactory(connectionFactory);
        return redisTemplate;
    }

}
redis:
    host: localhost
    port: 6379
#    password: 123456
    database: 0 #操作的是0号数据库
    jedis:
      #Redis连接池配置
      pool:
        max-active: 8 #最大连接数
        max-wait: 1ms #连接池最大阻塞等待时间
        max-idle: 4 #连接池中的最大空闲连接
        min-idle: 0 #连接池中的最小空闲连接

 配置文件也没有什么问题,但是就是一执行@autowried就会报Error creating bean with name 'redisTemplate'

按理来说应该是正常的

于是更换了一下maven坐标的版本结果解决了,应该就是版本与Springboot版本进行冲突导致的.更改为如下版本发现问题可以解决,redisTemplate对象可以正常注入了.

还有一点大家在进行redis的学习中,在springboot测试目录进行编写的话一定记得在测试类加上@RunWith(SpringRunner.class)注解,如果测试过程没加也会报些奇奇怪怪的错误!

  • 11
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值