Spring-cloud-config: Document howto share common properties for a subset of services

Created on 26 Jan 2017  路  7Comments  路  Source: spring-cloud/spring-cloud-config

We have several micro-services in our project that use the same config server (same git repository). Any common properties that are needed by more than one service/module are being placed in application.properties. So if serviceA and serviceB need a property, it will be placed in application.properties. But the problem is that this property will be available to rest of the services as well. This makes it harder for the dev ops team to configure the application.properties as they need to understand which specific properties apply to a particular service. For better manageability, we would also like to store these properties in separate files and have services load them up via config server.

So my questions are:
Is there any way we can share a common set of properties among a subset of services (and not all of them) without polluting the base application.properties? Is it possible to define multiple base files for a service? For example,

I would like to have multiple base property files like below:
application.properties
application-prod.properties
cassandra.properties
cassandra-prod.properties
jpa.properties
jpa-prod.properties
redis.properties
redis-prod.properties
async.properties
async-prod.properties

And configure a service to use just the property files that it needs. So serviceA and serviceB which use cassandra can be configured to use application.properties and cassandra.properties whereas ServiceC which needs jpa will be configured to use application.properties and jpa.properties

Please let me know if something like above is possible and if there are any approaches that might help in our case. Thanks in advance for any help/suggestions you can provide

documentation

Most helpful comment

Might be nice to add to the docs.

All 7 comments

Use profiles? At the very least application-cassandraprod.properties. I'm checking with the boot team to see if you can qualify with multiple profiles.

We use the boot mechanisms to load these files, so we don't want to stray from that.

The only special file in configserver is application.{yml|properties}, everything else is based off the application name passed in.

You could set, on the client side, spring.cloud.config.name=${spring.application.name},cassandra, and the profile prod, then it would pick up (if spring.application.name=foo): foo.properties, foo-prod.properties, cassandra.properties and cassandra-prod.properties.

That looks like it will work.

That's very good to know. I will test this and confirm the results soon. Thank you @spencergibb

Might be nice to add to the docs.

@spencergibb It is working as you described. Thank you very much! One thing I noticed is that the order of the names defined under spring.cloud.config.name matters. That is, if spring.application.name=cassandra,servicea then properties in servicea.properties file override any matching properties in cassandra.properties

Noted on ordering. That is because that is how the properties are ordered coming back from config server, so it does make sense to me.

Was this page helpful?
0 / 5 - 0 ratings