Reputation: 11
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.
Upvotes: 1
Views: 1766
Reputation: 496
My understanding is that OP were trying to run cloud config servers that serve only configs for specified env, i.e. so calling test
cloud config server with prod
profile won't leak credentials.
I managed to achieve that using pattern matching:
Example config:
spring:
cloud:
config:
server:
git:
uri: https://github.com/my-cloud-config/config-repo
repos:
per-env-config:
uri: ${spring.cloud.config.server.git.uri}
search-paths: '{application}'
pattern: '*/${TARGET_ENV}'
Config repository must have structure like this:
/app1/application-test.yml
/app1/application-prod.yml
/app2/application-test.yml
/app2/application-prod.yml
Because I didn't specified spring.cloud.config.server.git.search-paths
Spring will ignore /app1
and /app2
directories unless profile matches TARGET_ENV
.
Upvotes: 0
Reputation: 2346
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.
Upvotes: 0