【问题标题】:Docker compose spring boot redis connection issueDocker compose spring boot redis 连接问题
【发布时间】:2018-12-31 11:13:14
【问题描述】:

我正在运行一个简单的 rest 应用程序,redis 在 docker 容器/docker-compose 中运行。我相信,redis 必须可以使用 http://redis:6379 进行 Spring Boot 访问。但是,它会抛出错误:

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)

我的代码是here

【问题讨论】:

  • 你应该有redis的服务定义吗?

标签: docker spring-boot redis docker-compose


【解决方案1】:

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

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

或者,

改变

links:
 - "redis:localhost"

links:
 - "redis"

【讨论】:

    猜你喜欢
    • 2020-12-18
    • 2022-01-03
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 2019-06-06
    • 2020-07-12
    • 2018-01-11
    相关资源
    最近更新 更多