一、错误详细
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为你需要设置的密码