Springboot引入redis启动报错问题的解决
将spring-boot-starter-data-redis内部的lettuce依赖移除,并添加jedis客户端,springboot版本为2.2.1.RELEASE,在springboot项目pom文件中添加了下面依赖。
在springboot项目pom文件中添加了下面依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
后面老师说spring-boot-starter-data-redis默认使用的lettuce操作redis,在访问量大时报堆外内存溢出,参照老师的方法,对依赖作了下改动:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
将spring-boot-starter-data-redis内部的lettuce依赖移除,并添加jedis客户端,
<dependency>
<groupId>redis-clients</groupId>
<artifactId>jedis</artifactId>
<version>3.1.0</version>
</dependency>
启动后项目报错:
***************************
APPLICATION FAILED TO START
***************************
Description:
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 injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
The following candidates were found but could not be injected:
- Bean method 'redisConnectionFactory' in 'JedisConnectionConfiguration' not loaded because @ConditionalOnClass did not find required class 'org.apache.commons.pool2.impl.GenericObjectPool'
- Bean method 'redisConnectionFactory' in 'LettuceConnectionConfiguration' not loaded because @ConditionalOnClass did not find required class 'io.lettuce.core.RedisClient'
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:54336', transport: 'socket'
Process finished with exit code 0
springboot版本为2.2.1.RELEASE,
后面在原基础上添加下面依赖启动才正常:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)