Docker撰写Spring Boot Redis连接问题 [英] Docker compose spring boot redis connection issue

查看:177
本文介绍了Docker撰写Spring Boot Redis连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个简单的rest应用,其中 redis 在docker容器/ docker-compose中运行。我相信,必须使用 http:// redis:6379 来访问 redis 才能进行春季启动。但是,它引发了错误:

I am running a simple rest app with redis running in a docker container/docker-compose. I believe, redis must be accessible to spring boot using http://redis:6379. But, it throws the error:

018-07-22 21:53:33.972 ERROR 1 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool] with root cause

java.net.ConnectException: Connection refused (Connection refused)

我的代码是此处

推荐答案

由于您在链接中使用别名,因此必须使用主机名与访问容器的别名相同。
因此,您可以执行以下操作之一,

Since you are using alias in links, you have to use the hostname identical to the alias to access the container. Therefore you can do one of following,

使用 http: // p / localhost:6379 ,而不是Spring Boot应用程序中的 http:// redis:6379

use http://localhost:6379 instead of http://redis:6379 in your spring boot application

更改

links:
 - "redis:localhost"

links:
 - "redis"

这篇关于Docker撰写Spring Boot Redis连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆