SpringBoot整合redis使用redisTemplate出现异常org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.xxx.xxx.xxx:6379,redis安装在虚拟机中的Linux,尝试了许多帖子的解决方案都没成功,但也记录一下,最后也找到了自己出现异常的地方后成功解决。
1 依赖不兼容:redis7.04版本及springboot框架引用redis框架的lectture-core依赖版本太低出现不兼容问题。解决如下:
这是我springBoot的版本
相对应的lectture-core版本
2 application.yml中有关redis的配置信息如主机名、端口号正确配置
3 Linux中防火墙关闭或redis服务端的端口是开放的,可通过以下命令测试
在防火墙关闭时仍然不能连接端口,参照https://blog.51cto.com/u_11461281/2179025
4 redis配置文件注释掉bind 127.0.0.1以及将protected-mode yes改为no
5 正确指定启动redis的配置文件(我最后的错误),我是在linux中任意目录下使用redis-server /myredis/redis.conf(redis.conf在我机子中的副本)启动redis服务,但redis仍然使用的是原redis.conf文件,而原配置文件没有经过4中的修改,所以无法连接,最后是到myredis目录下启动redis服务端才能连接redis