Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 856
Zirzirikos Avatar asked Apr 19 '16 19:04

Zirzirikos


1 Answers

Probably it's too late already, but in case someone else is struggling with the same issue, the final solution is as follows:

You can create as many yml files under config-server classpath as you wish. Even if it is in native profile selected, there will be provided to client applications. The only thing not mentioned before is, you should tell the client application to read those settings files as well.

Here is a working example:

Config server file structure:

resources
|-config
   |-auth-service.yml - service specific configuration file
|-application.yml - config server settings
|-settings.yml - general settings file, planed to be loaded in every service

Client application bootstrap.yml file:

spring:
application:
  name: auth-service
cloud:
  config:
    username: "config-user"
    password: "config-password-1234"
    uri: "http://config-service:8888"
    name: ${spring.application.name}, settings

The key is name: ${spring.application.name}, settings which tells the config client to load the following settings from the config server:

  • ${spring.application.name} which will load config/auth-service.yml
  • settings which will load settings.yml
like image 138
Zsolt Tolvaly Avatar answered Oct 19 '22 00:10

Zsolt Tolvaly