有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我几乎没有环境。有:

  • 本地的
  • 发展
  • 试验
  • 质量保证
  • lod
  • 刺激

如果config server连接到所有服务器,则所有内容都将清除

在我的情况下,我需要每个组的配置服务器:

  • 在开发人员的控制下
  • 在qa控制下
  • 近devops控制

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

因此,我需要为每个客户提供如下服务:

引导。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引导文档,但没有遇到过bootstrap.yml评测

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

共 (1) 个答案

  1. # 1 楼答案

    有两种可能的解决方案可以为spring云配置服务器配置客户端:

    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
    

    附言

    方法可以是混合的