代码之家  ›  专栏  ›  技术社区  ›  Nishant Varshney

多个微服务的通用应用程序属性文件

  •  1
  • Nishant Varshney  · 技术社区  · 7 年前

    我想为多个微服务使用一个公共应用程序属性文件,这些微服务将具有一些公共配置,如db source config等。我将config server与eureka server和zull proxy一起使用。

    问题:

    使用configServer时,我们需要提供spring.application.name='xyz' 然后找到这个微服务配置的xyz.properties。

    同样,当我们用zuul代理注册服务时,配置服务路径也需要与zuul.routes.xyz.path=/iii/*相同的应用程序名。

    现在,我希望多个服务共享同一个属性文件(xyz.properties),但也需要注册zuul路由,因此我必须为每个服务提供不同的名称。如果我为每个服务提供不同的名称,它们将无法定位相同的属性文件。

    我刚开始使用Spring Boot Micro Services。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Barath    7 年前

    spring.config.client.name版本 支持用逗号分隔的多个名称以加载配置属性。

    在这种情况下,将公共属性存储在common.yml中,将xyz属性存储在xyz.yml中。最后,提到 spring.cloud.config.name: xyz,common

    spring:
      cloud:
        config:
          uri: http://localhost:8888
          name: xyz,common
    
    

    输出:

    Fetching config from server at : http://localhost:8888
    Located environment: name=xyz,common, profiles=[default], label=null, version=91edcf96c6a88707bf39014a16ad5d301d6b4575, state=null
    Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://github.com/BarathArivazhagan/config-server-repository/common.yml'}, MapPropertySource {name='https://github.com/BarathArivazhagan/config-server-repository/xyz.yml'}]}
    
    推荐文章