Docker撰写Spring Boot Redis连接问题

时间:2018-07-23 23:08:38

标签: docker spring-boot redis docker-compose

我正在运行一个简单的rest应用,其中redis在docker容器/ docker-compose中运行。我相信,redis必须可以使用http://redis:6379进行春季引导。但是,它会引发错误:

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

1 个答案:

答案 0 :(得分:2)

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

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

更改

links:
 - "redis:localhost"

links:
 - "redis"