BeanNotOfRequiredTypeException: Bean named ‘stringRedisTemplate‘...

报错:

[ERROR] Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisUtils': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'stringRedisTemplate' is expected to be of type 'org.springframework.data.redis.core.StringRedisTemplate' but was actually of type 'org.springframework.data.redis.core.RedisTemplate':
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'stringRedisTemplate' is expected to be of type 'org.springframework.data.redis.core.StringRedisTemplate' but was actually of type 'org.springframework.data.redis.core.RedisTemplate'

项目A依赖于项目B,引入的B的包
B中有一工具类RedisUtils被依赖进来

@Component
public class RedisUtils {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
	...
}

B中StringRedisTemplate的类型是
org.springframework.data.redis.core.StringRedisTemplate
在这里插入图片描述

而A也引入了StringRedisTemplate,类型是
org.springframework.data.redis.core.RedisTemplate
在这里插入图片描述

因为@Resource,根据名称自动注入,所以引入了A里的StringRedisTemplate,导致了报错

解决方式:将B的工具类中,@Resource改为@Autowired(required=false)(根据类型引入,没有也可以)即可

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值