Search code examples
javaspringspring-bootspring-cloudspring-cloud-config

Include common config for multiple apps in Spring Cloud Config server


I'm trying to migrate our stable of app servers to get their configuration from a Spring Cloud Config server. Each app has a {my-app}.yml file on the config server and we can use profiles (either in files named {my-app}-{profile}.yml or using multi-profile YAML documents) to have different configuration per environment for each app, and we can even include one profile in another using spring.profiles.include to provide some sort of inheritance - so far, so good.

However, we can only include profiles from the same app in each other and we have several apps configured from the same config server which share a lot of config per environment - for instance they almost all use the same DataSource config to connect to the same database and likewise for messaging, cache and so on. That's a lot of duplicated config and a lot of places it needs to be changed - precisely what Spring Cloud Config is supposed to avoid!

Is there a way to "include" (via profiles or otherwise!) shared config properties across apps in Spring Cloud Config server?

Update

In addition to the correct answer by @vladsfl below, beware if you're using the native profile on the config server to serve config from the filesystem or classpath instead of a git repo, the config server will use application.yml and its profile variants for itself but refuse to serve them out to other apps. The solution is to use spring.cloud.config.server.native.searchLocations to pull the served config from a different location.


Solution

  • Yes. You can have application.yml or application-<profile>.yml on your config server and now every application that is using this config server will inherit all settings in application.yml. Every application that runs in specific profile will inherit settings from application-<profile>.yml.