nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379

21 篇文章 2 订阅
5 篇文章 0 订阅

一、错误详细

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'captchaController': Unsatisfied dependency expressed through field 'configService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysConfigServiceImpl': Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is 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 localhost:6379
	org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysConfigServiceImpl': Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is 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 localhost:6379
	
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is 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 localhost:6379
	
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
	
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:6379
Caused by: java.net.ConnectException: Connection refused: no further information
	

二、错误分析

上面截取的是idea控制台启动报错的信息,我截取了部分片段,即每段报错信息的开头,通过报错信息,我们能很直观的看到是因为无法连接Redis而抛出的异常。
但是我的Redis是用的本地的Redis,而且我的Redis已经开启,那为什么会报错呢。
在这里插入图片描述
我去看了一下配置文件,我的配置文件里面是给Redis设置了密码的。
在这里插入图片描述
但是我的Redis服务端并没有设置密码。通过以下命令查看Redis的密码

config get requirepass

在这里插入图片描述
所以问题找到了,是因为后端配置和Redis配置不一样。

三、问题解决

在项目启动时,我们需要Redis的配置和配置文件里面的配置保持一直。必须保持后端和Redis同时拥有密码或者同时不拥有密码。
如果Redis没有密码,就需要在配置文件中将password一行删掉。或者在Redis中设置与后端配置文件相同的密码。
Redis设置密码:在redis-cli命令行中输入

config set requirepass 123456
# 其中123456为你需要设置的密码

在这里插入图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

igxia

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值