昨天在做RedisTemplate连接Redis时,启动报错,报错内容如下
level-ERROR - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379] with root cause
java.net.ConnectException: Connection refused: no further information
检查了一下,Redis的配置没有问题,也正常启动了,ip地址和端口号也没有配置错误,Linux防火墙也关掉了。代码都没有问题,配置也没有问题,但就是无法启动。百度了好久也没有找到解决方法。今天总于是把问题解决了。
原因是,这是这个项目第一次连接Redis,之前的其它项目连接完Redis后,Redis中产生了缓存,导致Redistemplate无法连接Redis,具体为什么这样我现在也不太清楚。
解决方法就是:把Redis数据库清空,并且把rdb和aof持久化文件删除,重启Redis,就搞定了。