小编典典

Docker撰写Spring Boot Redis连接问题

redis

我正在运行一个简单的rest应用程序,redis并在docker容器/ docker-compose中运行。我相信,redis必须使用Spring
Boot才能访问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)

我的代码在这里


阅读 718

收藏
2020-06-20

共1个答案

小编典典

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

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

要么,

更改

links:
 - "redis:localhost"

links:
 - "redis"
2020-06-20