参考 Redis 连接错误/连接池配置错误

问题

【说明】:项目采用Redia在redis方面采用RedisTemplate进行方法调用,在配置中采用RedisConnectionFactory和redis连接池

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2020-11-11 17:53:58.782 ERROR 18680[ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name ‘userController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name ‘userServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name ‘redisService’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘redisTemplate’ defined in class path resource [com/neusiri/config/RedisConfig.class]: Unsatisfied dependency expressed through method ‘redisTemplate’ parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘redisConnectionFactory’ defined in class path resource [org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: 
Factory method ‘redisConnectionFactory’ threw exception; 
nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig

解决

 <!--redis依赖-->
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
  </dependency>
  <!--连接池依赖-->
  <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-pool2</artifactId>
  </dependency>

【配置文件中redis配置信息】

#配置redis信息
#redis服务器地址
spring.redis.host=localhost
#redis服务器端口
spring.redis.port=6379
#连接池最大连接数(使用负数表示没有限制)默认8
spring.redis.lettuce.pool.max-active=100
#连接池最大阻塞等待时间(使用负值表示没有限制)默认-1
spring.redis.lettuce.pool.max-wait=PT10S
#连接池最大空闲连接数(使用负值表示没有限制)默认8
spring.redis.lettuce.pool.max-idle=30
#连接池最小空闲连接数(使用负值表示没有限制)默认0
spring.redis.lettuce.pool.min-idle=1
#连接超时时间
spring.redis.timeout=PT10S

【注】刷新Maven=>重启

Logo

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

更多推荐