gpt4 book ai didi

spring-boot - Spring Cloud Config Server 无法与 Docker compose 一起使用

转载 作者:行者123 更新时间:2023-12-02 21:50:56 29 4
gpt4 key购买 nike

我有一个 Spring Cloud 配置服务器并将其打包为 Docker 镜像,然后我有 Spring Cloud Eureka 服务器,它也打包为 Docker 镜像。

当我使用 docker compose 运行这两个时,出现以下错误。

discovery-service_1 | 2017-06-24 15:36:12.059 INFO 5 --- [ main] c.c.c.ConfigServicePropertySourceLocator :从服务器获取配置:http://config-service:9001
发现服务_1 | 2017-06-24 15:36:12.997 WARN 5 --- [ main] c.c.c.ConfigServicePropertySourceLocator :无法找到 PropertySource:“http://config-service:9001/cls-discovery-service 的 GET 请求出现 I/O 错误/default”:连接被拒绝(Connection returned);嵌套异常是java.net.ConnectException:连接被拒绝(连接被拒绝)

Although the config service is up and running successfully, discover service still does not find it for some reason.

这里使用的 Docker compose 文件是这个
版本:'2'
服务:
配置服务:
图片:cloudsea/cls-config-service
端口:
- 9001:9001
暴露:
- “9001”
发现服务:
图片:cloudsea/cls-discovery-service
依赖于取决于:
- 配置服务
环境:
CLOUD_SEA_CONFIG_SERVER_URI:http://config-service:9001
EUREKA_DEFAULT_ZONE_URL:http://discovery-service:8761/eureka/
端口:
- 8761:8761
链接:
- 配置服务:配置服务

下面是 DISCOVERY SERVICE 的 bootstrap.properties

spring.cloud.config.uri = ${CLOUD_SEA_CONFIG_SERVER_URI:http://localhost:9001}
spring.application.name = ${SPRING_APPLICATION_NAME:cls-discovery-service}

下面是位于 github 中的 DISCOVERY SERVICE 的 cls-discovery-service.properties

server.port=${SERVER_PORT:8761}
eureka.client.registerWithEureka: false
eureka.client.fetchRegistry: false
eureka.client.serviceUrl.defaultZone: ${EUREKA_DEFAULT_ZONE_URL:http://localhost:8761/eureka/}
eureka.server.eviction-interval-timer-in-ms:1000

我假设我的 docker-compose.yml 有问题,但我不确定。

有什么帮助吗?我会坚持几个小时......接近几天:(

最佳答案

我通过将此配置添加到发现服务的 bootstrap.yml 中解决了这个问题。

spring:
cloud:
config:
failFast: true
retry:
initialInterval: 3000
multiplier: 1.3
maxInterval: 5000
maxAttempts: 20

然后将spring-boot-starter-aopspring-retry添加到发现服务的maven依赖项中。

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>${spring-boot-starter-aop.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>${spring-retry.version}</version>
</dependency>

问题是它们同时开始。但发现服务依赖于配置服务。

当您启动发现服务时,它会一遍又一遍地显示“正在从服务器获取配置”,直到配置服务启动。

配置服务启动后,发现服务将成功获取其配置,然后它将自行启动。

关于spring-boot - Spring Cloud Config Server 无法与 Docker compose 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44738469/

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