Search code examples
spring-bootmicroservicesnetflix-eurekanetflix-zuulspring-cloud-config

Common application property file for multiple microservice


I want to use a common application properties file for multiple microservices which will have some common configuration like DB Source config etc..I have use the config Server with Eureka server and zull Proxy.

Issue:

When using configServer we need to provide the spring.application.name = 'xyz' which in turn find the xyz.properties for this microservice configuration.

The same way when we register the service with zuul proxy also need the same application name for configure the service path as zuul.routes.xyz.path = /iii/*.

Now I want that multiple service will share the same property file(xyz.properties) but need to register the zuul route as well so I have to provide the different name for each service. If I will provide the different name to each service they will not be able to locate the same property file.

I am new to spring boot micro services.


Solution

  • spring.config.client.name supports multiple names separated by commas to load the configuration properties.

    In this case, store the common properties in common.yml and xyz properties in xyz.yml. Finally, mention spring.cloud.config.name: xyz,common

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

    Output:

    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'}]}