gpt4 book ai didi

docker - Docker-SpringConfig-连接被拒绝到ConfigServer

转载 作者:行者123 更新时间:2023-12-02 21:23:16 26 4
gpt4 key购买 nike

我正在尝试使用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会在最后包含 / user-server-config / desa 包含 http://localhost:8888 。代替application.yml中指示的 http://server-config:8888

最佳答案

根据spencergibb的建议here并根据official documentation的建议,创建一个bootstrap.yml文件:

spring:
cloud:
enabled: true
config:
uri: http://config-server:8888
failFast: true
retry:
maxAttempts: 20

并从 application.yml中删除上述包含的属性。

关于docker - Docker-SpringConfig-连接被拒绝到ConfigServer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43005558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com