0

I'm working with spring cloud config server, and my need is to create a configuration file for each stage prod test and dev, I already created 4 yml file application.yml for the default profile, application-{profiles} for each profile, so my question is how to load the specific configuration through the environment variable and run the config server on each profile configuration and port , I already created a bootstrap.yml but I can't solve the issue. I will be very thankful if someone can guide throught the steps to achieve my need.

ahmed70
  • 1
  • 1
  • 4

1 Answers1

0

You don't need to start Spring Cloud Config Server with different profiles and on different port per environment. You can have one Config Server that manages the configurations for all environments. In your client's bootstrap.yml you will need to provide the URL of your Config Server as follows:

spring:
  cloud:
    config:
      uri: http://your-config-server

When you run your client application with a particular profile (e.g. via an environment variable spring_profiles_active=dev), Spring Cloud Config Client will fetch the configuration properties from Config Server for the targeted profile.

I recommend to review at least the Quick Start section of the Spring Cloud Config documentation and try the examples provides there.

Gregor Zurowski
  • 2,222
  • 2
  • 9
  • 15
  • thanks for your reply, the idea is my company requirement need to run the config server itself based on the profile either prod dev and so on. – ahmed70 Jul 13 '21 at 08:15
  • As far as I understand, you want to run a config server deployment per environment. If you do that, you would need to define the config server URI as provided in my answer per profile. This can be achieved by Spring profiles and the corresponding `bootstrap.yml` files (e.g. `bootstrap-dev.yml`, `bootstrap-prod.yml`, etc.), or alternatively inject the config server URI through the environment (a variable such as `CONFIG_SERVER_URI`) and reference it in `bootstrap.yml` with a placeholder property as follows: `spring:cloud:config:uri: ${CONFIG_SERVER_URI:http://localhost:8888}`. – Gregor Zurowski Jul 13 '21 at 08:39
  • Please also see the following post related to what I mentioned above: https://stackoverflow.com/questions/36934873/set-profile-on-bootstrap-yml-in-spring-cloud-to-target-different-config-server – Gregor Zurowski Jul 13 '21 at 08:41
  • Thnx for your reply, I have implemented it with the same concept : create application.yml for each profile and then run server based on the specific profile – ahmed70 Jul 14 '21 at 09:13