Redis集成SpringDataRedis问题:Could not get a resource from the pool

本文介绍了在使用SpringDataRedis过程中遇到的Couldnotgetaresourcefromthepool问题及其解决办法,包括重启Redis服务、利用工具类关闭连接以及采用SpringAOP进行资源释放。

Redis集成SpringDataRedis问题:Could not get a resource from the pool

今天在Redis集成SpringDateRedis的案例上遇到了一个问题:
HTTP Status 500 - Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method findByCategoryId in the service
后面的报错原因貌似是尝试了三次超时,我一开始以为是RedisTemplate没有注入成功,但是仔细查看配置文件发现bean都配置的好好的。重开一个test项目后,使用JUnit集成spring测试SpringDataRedis,发现它报错换了一个方式,就是标题所说的:Could not get a resource from the pool,大概的意思是无法从池子里获得资源。
在网上查阅资料后,发现SpringDataRedis在使用RedisTemplate后是不会自动释放资源的,而资源都被占用自然获取不到连接对象,所以有几种方法可以使用:

  1. 暴力法:重开redis服务器
  2. 采用工具类:工具类包装一个方法关闭连接对象,在使用完资源后调用释放
  3. spring aop:采用切面方法,包装一个after方法,自动在方法使用后调用释放资源
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值