How to read multiple config file from Spring Cloud Config Server

David.Wang picture David.Wang · May 13, 2017 · Viewed 9.4k times · Source

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?

Answer

yongsung.yoon picture yongsung.yoon · May 14, 2017

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