Bean named ‘redisTemplate‘ is expected to be of type ‘org.springframework

109 阅读1分钟

报错:Bean named ‘redisTemplate‘ is expected to be of type ‘org.springframework

theme: hydrogen highlight: a11y-dark

Bean named 'redisTemplate' is expected to be of type 'org.springframework.data.redis.core.StringRedisTemplate' but was actually of type 'org.springframework.data.redis.core.RedisTemplate'

我自己写的是:

 @Resource
 private StringRedisTemplate redisTemplate;

解决方案:

@Autowired  
private StringRedisTemplate redisTemplate;

原因@Resource是默认取字段名(变量名)进行按照名称注入,而我们的变量名是redisTemplate,我们没配置这个类型。