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

时间:2019-08-05 10:55:38

标签: java spring-boot spring-cloud-config spring-profiles

我的环境很少。有:

  • 本地
  • dev
  • 测试
  • qa
  • lod
  • 产品

如果配置服务器连接到所有服务器,一切都会清除。

就我而言,我需要每个组的配置服务器:

  • 在开发人员的控制之下
  • 在质量检查控制下
  • 靠近devops的控制区

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

所以我需要每个客户类似的东西

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

哪里

  • local-dev-test-configuration-server将有权访问localdevtest服务器配置;
  • qa-configuration-server将有权访问qa配置;
  • lod-prod-configuration-server仅可以访问prodlod配置。

问题:

我研究了Spring Boot文档,但没有遇到bootstrap.yml分析。

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

1 个答案:

答案 0 :(得分:0)

有两种可能的解决方案为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。

方法可以混合。

相关问题