【问题标题】:Spring cloud config local and remote repositories for different profilesSpring Cloud 为不同的配置文件配置本地和远程存储库
【发布时间】:2016-12-17 15:43:33
【问题描述】:

我正在尝试使用多个存储库设置我的应用程序 - 一个基于本地文件的用于开发/测试目的的存储库和一个用于生产的远程 git 存储库。

我为此目的使用以下 yaml -

spring:
  application:
    name: localRepoConfig
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo
          repos:
            development:
              pattern:
                - '*/development'
                - '*/staging'
              uri: https://github.com/development/config-repo          
        native:
          searchLocations: classpath:/config
server:
  port: 8888

但是,这不起作用,以下适用于本地 repo -

spring:
  application:
    name: localRepoConfig
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          searchLocations: classpath:/config
server:
  port: 8888

在遵循 Spring 文档和此处的一些帖子之后,我无法使这两个存储库发挥作用。 如果有人能指出我正确的方向,将不胜感激。

【问题讨论】:

  • 更正了您的格式。通常,您只在执行单行代码时才使用 `。多行代码应缩进 4 个空格以使其显示为代码块。
  • +1 的想法:> 一个基于本地文件的用于开发/测试目的的文件和一个用于生产的远程 git repo。

标签: spring spring-boot yaml spring-cloud-config


【解决方案1】:

我在 bootstrap.yml 中使用以下配置进行了这项工作 -

spring: application: name: localRepoConfig profiles: active: native cloud: config: server: native: searchLocations: classpath:/config server: port: 8888

--- spring:
profiles: development cloud: config: server: git: uri: https://github.com/spring-cloud-samples/config-repo server: port: 8989

我现在可以在原生配置文件和开发配置文件之间切换。 以下指南非常有帮助 - kubecloud.io/guide-spring-cloud-config/

【讨论】:

    【解决方案2】:

    根据 Spring Cloud Config 上的文档,听起来 native 和 git 是互斥的,您不能将两者用于单个配置服务器。

    【讨论】:

    • 感谢肖恩回复。有没有其他方法可以拥有这两种配置,这样我就可以使用不同的配置文件在它们之间切换..?
    猜你喜欢
    • 2019-08-11
    • 2019-06-30
    • 1970-01-01
    • 2012-01-13
    • 2011-06-29
    • 2021-04-18
    • 2021-03-29
    • 2014-01-23
    • 1970-01-01
    相关资源
    最近更新 更多