14

I currently have a number of deployable applications that work in a distributed fashion to solve a business problem. We are currently using a number of property configuration files to provide changing configuration per environment based off a system environment variable. All these deployable application share common configuration for database and messaging. This is currently achieved by picking up property files from the class path and having both deployed apps share a common jar for each connection (db, jms) containing property files.

I am looking to start using Spring Config Server to externalize this configuration if possible. I have a question about how to share this common config.

Currently it looks something like this:-

Web1
- database
- jms

Messaging1
- database
- jms

In this situation both deployed apps share the same connections and these connections change per environment (lab, prf, prd, etc). How can I achieve the same with the Spring Configuration Server where I have app config for each deployable app?

Application.yml
Web1.yml
Web1-dev.yml
Messaging1.yml
Messaging1-dev.yml

If a connection property changed for an environment I would need to make the change to each deployable app configuration rather than making it just once.

Is there currently anyway to achieve this? Am I just missing a simple point?

Wojciech Wirzbicki
  • 2,990
  • 4
  • 27
  • 47
Jeffxor
  • 181
  • 1
  • 6
  • 2
    I have the same problem and wondering if it is really so uncommun to have multiple applications share parts of there configs. – ssindelar Nov 20 '15 at 13:40
  • Related https://stackoverflow.com/questions/35555232/loading-multiple-properties-with-config-server – pramodc84 Mar 01 '18 at 09:35

3 Answers3

9

I found working solution here https://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html, paragraph "2.1.5 Sharing Configuration With All Applications". It says:

With file-based (i.e. git, svn and native) repositories, resources with file names in application* are shared between all client applications (so application.properties, application.yml, application-*.properties etc.). You can use resources with these file names to configure global defaults and have them overridden by application-specific files as necessary.

You should create application.properties or application.yml at the top level of configuration repository (if it is git or svn based). Don't forget to commit the changes.

Wojciech Wirzbicki
  • 2,990
  • 4
  • 27
  • 47
  • 1
    Works good also with database repo. Just set "application" as the value of the application column. – Ronen Jan 15 '19 at 15:15
  • Correct me if I'm wrong, but this means that if I set properties in application-dev.yaml, all my applications using the dev profile will inherit those properties, right? – Dylan Colaco Feb 08 '19 at 09:00
  • @Ronen Does the same thing apply for profile? Just set the profile field equal to "profile" to have it apply to all profiles? – RobOhRob Dec 17 '19 at 19:45
  • Anybody wondering the same thing... profile needs to be inserted as 'default' in order for it to apply to all profiles – RobOhRob Dec 20 '19 at 15:04
  • @RobOhRob, No, to apply for all profiles you need to set the profile to "default" – Ronen Dec 31 '19 at 07:10
4

This is how I have configured for my setup.

1 All Common properties across all services and environments will be in root->application.properties files

2 All Common properties across all environments specific to service will be root->service-X.properties files

3: Similarly, to have common properties across specific environment use env->application.properties file

server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri:[git repo]
          search-paths: /,/{profile}/

enter image description here

Niraj Sonawane
  • 6,954
  • 7
  • 49
  • 76
3

Finally found a solution. It's buried in the issues at github ...

https://github.com/spring-cloud/spring-cloud-config/issues/32

It worked liked described. I only noticed, that you need to put the files in a /config folder to make it work. If you put it in the root the file ist used by the configserver itself and is not included in the config requests.

ssindelar
  • 2,743
  • 1
  • 13
  • 36