我有一个简单的Spring云项目,它包含4项服务:
如果在localhost中部署项目没有问题,
我可以通过zuul成功获取service-1的api而无需使用docker:
但是当我使用docker部署时,
它抛出错误:Caused by: java.lang.RuntimeException: org.apache.http.conn.HttpHostConnectException: Connect to registry:9527 [registry/172.21.0.4] failed: Connection refused (Connection refused)
我只能使用service-1的api
获取PS:两个服务(网关,服务-1)已成功注册到eureka
这是我的docker-compose yml:
version: '3'
services:
config:
build: ./config
ports:
- "8888:8888"
registry:
build: ./registry
ports:
- "8761:8761"
depends_on:
- config
environment:
- SPRING_PROFILES_ACTIVE=prd
gateway:
build: ./gateway
depends_on:
- config
links:
- registry
- service-1
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=prd
service-1:
build: ./service-1
ports:
- "9527:9527"
depends_on:
- config
links:
- registry
environment:
- SPRING_PROFILES_ACTIVE=prd
任何人都可以帮助我吗?
答案 0 :(得分:0)
我已经解决了这个问题,我忘了在网关主类上添加@EnableDiscoveryClient
,并覆盖eureka实例主机名