为每个配置文件组配置 spring 云配置服务器

Configure spring cloud config server for each profile group

我的环境很少。有:

如果配置服务器连接到所有这些,一切都清楚了。

在我的例子中,我需要每组配置服务器:

组连接到权限和不同的环境。

所以我需要为每个客户提供类似的东西:

bootstrap.yml

# default configs for local, dev, test profiles
spring:
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://local-dev-test-configuration-server:8888

---
# **bootstrap-qa.yml**
spring:
  profiles: qa
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://qa-configuration-server:8888

---
# **bootstrap-prod.yml**
spring:
  profiles: prod,lod
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://lod-prod-configuration-server:8888

在哪里

问题:

我研究了 spring 引导文档,但我没有遇到 bootstrap.yml 分析。

  1. 我应该遵循哪种方式来满足我的需求(管理 3 个不同的配置服务器和相应的配置文件)?
  2. 我检测到可以 configure different git resources 用于相同的配置服务器。这种方法是否最适合我的情况(我还必须管理几个存储库以保留所需的配置)?我不这么认为。由于可见性不同,我需要为不同的环境配置很少的配置服务器。因此,我需要根据配置文件对每个消费者配置主机名进行配置。

为 spring-cloud-configuration-servers 配置客户端有两种可能的解决方案:

  1. spring-boot 支持 bootstrap.yml 中的配置文件,因此提供的配置可以用作解决方案
spring:
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://local-dev-test-configuration-server:8888
---
spring:
  profiles: qa
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://qa-configuration-server:8888

---
spring:
  profiles: prod,lod
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://lod-prod-configuration-server:8888
  1. 如果您想使 bootstrap.yml 配置尽可能简单:
spring:
  application:
    name: discovery-service
  cloud:
    config:
      uri: http://local-dev-test-configuration-server:8888

在这种情况下,解决方案是使用 -Dspring.cloud.config.uri=http://localhost:8888 需要的参数覆盖 属性 例如:

java -Dspring.profiles.active=localhost -Dspring.cloud.config.uri=http://localhost:8888 -jar ./target/discovery-service-0.0.1-SNAPSHOT.jar

P.S.

方法可以混合使用。