Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring cloud config : how to use multiple configs

What I want to try:

I want to try the spring cloud config for microservice project where I have a common config for all services and multiple configs for each service.
I got idea on how to use multiple profiles using spring.profiles.active and include. I am trying to understand how can I load multiple configs on config client?

What I have:

In my git repo I have spring-config-repo where I have ...

application.yml
orderclient.yml
subscriberclient.yml
jmsclient.yml
productclient.yml

I have my config Server pointed to my config repo.

spring:
  application:
  name: config-service
  cloud:
   config:
    server:
      git:
        uri: https://github.com/<user>/spring-config-repo

server:
 port: 8888

I have my spring client where I want to use multiple configs. Here in my case for orderService I want to load application.yml,orderclient.yml,jmsconfig.yml and For Product microService I need 'orderconfig.yml,jmsclient.yml,productclient.yml'

spring:
application:
  name: orderclient
profiles:
  active: test
cloud:
  config:
    uri: http://localhost:8888

###Any kind of config properties to load jmsclient, productclient?

Above I can access properties from orderclient.yml.

My Question:

Question1:

How to access properties of jmsclient.yml,productclient.yml in orderclient application.

Question2:

Is there anyway to get list of all propertySources.name exposed by config server? where in above case it should dispaly

"propertySources": {
  "name": "https://github.com/<>/spring-config-repo/aplication.yml",
     "profiles": <available profiles for this say> Dev, Test,
  "name": "https://github.com/<>/spring-config-repo/orderclient.yml",
     "profiles": <available profiles for this say> Dev, Test
  "name": "https://github.com/<>/spring-config-repo/jmsclient.yml",
     "profiles": <available profiles for this say> Dev, Test
 ....}

Please let me know if my question is not clear or need more information. Thanks.

like image 607
user1653027 Avatar asked Aug 29 '16 21:08

user1653027


People also ask

Can we have multiple configuration files in spring boot?

To add different files you can use the spring. config. location properties which takes a comma separated list of property files or file location (directories). The one above will add a directory which will be consulted for application.

What is the advantage using spring cloud config?

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments.


1 Answers

You can set a comma-separated list of configurations you want to load using spring.cloud.config.name property:

spring.cloud.config.name: jmsclient,productclient,orderclient
like image 131
pomkine Avatar answered Oct 21 '22 09:10

pomkine