Search code examples
spring-cloudspring-cloud-config

How to read multiple config file from Spring Cloud Config Server


Spring cloud config server supports reading property files with name ${spring.application.name}.properties. However I have 2 properties files in my application.

a.properties
b.properties

Can I get the config server to read both these properties files?


Solution

  • Rename your properties files in git or file system where your config server is looking at.

    a.properties -> <your_application_name>.properties
    a.properties -> <your_application_name>-<profile-name>.properties
    

    For example, if your application name is test and you are running your application on dev profile, below two properties will be used together.

    test.properties
    test-dev.properties
    

    Also you can specify additional profiles in bootstrap.properties of your config client to retrieve more properties files like below. For example,

    spring:
      profiles: dev
      cloud:
        config:
          uri: http://yourconfigserver.com:8888
          profile: dev,dev-db,dev-mq
    

    If you specify like above, below all files will be used together.

    test.properties
    test-dev.properties
    test-dev-db.prpoerties
    test-dev-mq.properties