在开发的过程中,有发展了redis使用的一个小坑,在这里分享下

错误如下:
Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'redisConnectionFactory' in 'JedisConnectionConfiguration' not loaded because @ConditionalOnClass did not find required classes 'org.apache.commons.pool2.impl.GenericObjectPool', 'redis.clients.jedis.Jedis'
    - Bean method 'redisConnectionFactory' in 'LettuceConnectionConfiguration' not loaded because @ConditionalOnClass did not find required class 'io.lettuce.core.RedisClient'

这个问题可能是使用哪个包的问题,首先要搞清楚

spring-boot-starter-data-redis和spring-data-redis两者这间的关系,可以打开spring-boot-starter-data-redis看下就知道了,里面有依赖了spring-data-redis相关

如果使用的是spring-data-redis这个,需要添加以下代码:
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>3.2.0</version>
</dependency>

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐