Docker - SpringConfig - 拒绝连接到 ConfigServer
Docker - SpringConfig - Connection refused to ConfigServer
我正在尝试使用 DockerCompose 使用远程存储库部署 ConfigServrService 和客户端。
docker-compose.yml就像:
version: '2'
services:
rabbitmq:
image: rabbitmq
ports:
- "5672:5672"
config-server:
image: config-server
environment:
- "SPRING_PROFILES_ACTIVE=desa"
ports:
- "8888:8888"
links:
- rabbitmq
depends_on:
- rabbitmq
user-service-config:
image: user-service-config
environment:
- "SPRING_PROFILES_ACTIVE=desa"
ports:
- "8090:8090"
links:
- config-server
- rabbitmq
depends_on:
- rabbitmq
- config-server
在部署时,客户端控制台显示:
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server
at: http://localhost:8888
(而不是 http://config-server:8888)
之后,控制台显示:
Could not locate PropertySource: I/O error on GET request for
"http://localhost:8888/user-server-config/desa": Connection refused;
nested exception is java.net.ConnectException: Connection refused
该服务正在尝试连接到 http://localhost:8888/user-server-config/desa 而不是 http://config-server:8888.
客户端的application.yml文件为:
server:
port: 8090
spring:
rabbitmq:
host: 172.17.0.1
port: 5672
username: guest
password: guest
application:
name: user-server-config
cloud:
enabled: true
config:
uri: http://config-server:8888
failFast: true
retry:
maxAttempts: 20
management:
security:
enabled: false
我不知道为什么 uri 包含 http://localhost:8888 with /user-server-config/desa at the end. Instead of http://server-config:8888,如 application.yml
中所示
按照spencergibb , and as the official documentation的建议,创建一个bootstrap.yml
文件:
spring:
cloud:
enabled: true
config:
uri: http://config-server:8888
failFast: true
retry:
maxAttempts: 20
并从 application.yml
.
中删除上述包含的属性
我正在尝试使用 DockerCompose 使用远程存储库部署 ConfigServrService 和客户端。
docker-compose.yml就像:
version: '2'
services:
rabbitmq:
image: rabbitmq
ports:
- "5672:5672"
config-server:
image: config-server
environment:
- "SPRING_PROFILES_ACTIVE=desa"
ports:
- "8888:8888"
links:
- rabbitmq
depends_on:
- rabbitmq
user-service-config:
image: user-service-config
environment:
- "SPRING_PROFILES_ACTIVE=desa"
ports:
- "8090:8090"
links:
- config-server
- rabbitmq
depends_on:
- rabbitmq
- config-server
在部署时,客户端控制台显示:
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
(而不是 http://config-server:8888)
之后,控制台显示:
Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/user-server-config/desa": Connection refused; nested exception is java.net.ConnectException: Connection refused
该服务正在尝试连接到 http://localhost:8888/user-server-config/desa 而不是 http://config-server:8888.
客户端的application.yml文件为:
server:
port: 8090
spring:
rabbitmq:
host: 172.17.0.1
port: 5672
username: guest
password: guest
application:
name: user-server-config
cloud:
enabled: true
config:
uri: http://config-server:8888
failFast: true
retry:
maxAttempts: 20
management:
security:
enabled: false
我不知道为什么 uri 包含 http://localhost:8888 with /user-server-config/desa at the end. Instead of http://server-config:8888,如 application.yml
中所示按照spencergibb bootstrap.yml
文件:
spring:
cloud:
enabled: true
config:
uri: http://config-server:8888
failFast: true
retry:
maxAttempts: 20
并从 application.yml
.