Liping Huang
Liping Huang

Reputation: 4476

spring cloud config best practice?

For the spring based project, for example, there are eureka config(eureka.properties), zuul config(zuul.properties), feign config(feign.properties) etc..

And also there are multiple environments like dev, test, staging, like application-dev.properties, application-prod.properties.

After introduced the spring cloud config to the project, we can keep all the config file to the git repo, but how to organize those config files well? and minimize the spring cloud client project's config?

Upvotes: 2

Views: 2760

Answers (1)

Liping Huang
Liping Huang

Reputation: 4476

Seems I misunderstood the spring cloud config at the beginning, with documentation

The HTTP service has resources in the form:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

where the "application" is injected as the spring.config.name in the > SpringApplication (i.e. what is normally "application" in a regular Spring Boot > app), "profile" is an active profile (or comma-separated list of properties), and > "label" is an optional git label (defaults to "master".)

With the spring cloud config built-in mechanism, the spring cloud config will expose all the properties as the REST resources, so where:

  • application is the spring boot client project spring.application.name
  • profile is the spring.profiles.active in the spring boot client project
  • label is the git branch name where git git repo is specific by the spring cloud config server , e.g. spring.cloud.config.server.git.uri

Then the client can GET all the properties against the rules above.

Normally for a spring boot client project, just need to config the spring cloud config server like:

spring:
  application:
    name: eureka
  cloud:
    config: 
      uri: http://localhost:8888
  profiles:
    active: dev, prod

So the client will GET all the properties: eureka-dev.yml and eureka-prod.yml in the spring cloud config server.

Upvotes: 2

Related Questions