架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

搜索
查看: 12733|回复: 0

[资料] Error creating bean with name 'stringRedisTemplate' defined in...

[复制链接]
发表于 2019-3-11 13:31:52 | 显示全部楼层 |阅读模式
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stringRedisTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'stringRedisTemplate' 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
环境:

spring-boot-starter-data-redis 2.1.1.RELEASE版本

spring-boot-starter-parent 2.1.1.RELEASE版本

jdk 1.8

POM.XML配置




启动项目报错,错误原因分析:

springboot 2.X 版本使用lettuce连接池来替换jedis。Lettuce和Jedis都是连接Redis Server的客户端程序,Jedis在实现上是直连redis server,多线程环境下非线程安全,除非使用连接池,为每个Jedis势力增加物理连接。Lettuce基于Netty的势力连接,可以再多个线程间并发访问,且线程安全,满足多线程环境下的并发访问,同时它是可伸缩的设计,一个连接实例不够的情况也可以按需增加连接实例。

解决办法:

springboot2.X默认使用lettuce连接池,需要引入commons-pool2



题外话,如果出现如下错误:

Consider defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration.

The injection point has the following annotations:
        - @org.springframework.beans.factory.annotation.Autowired(required=true)
请参考:

SpringBoot中注入RedisTemplate实例异常解决
https://www.itsvse.com/thread-7224-1-1.html
(出处: 架构师_程序员)






上一篇:SpringBoot中注入RedisTemplate实例异常解决
下一篇:解决Spring boot中文乱码问题
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2025-6-16 17:53

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表