Reputation: 11
Recently, I build a spring cloud config server for company business, the config server configuration like flw:
spring:
application:
name: config-server
cloud:
config:
label: master
server:
git:
uri: http://gitlab.ugirls.com:9999/commonconfig.git
search-paths: db,redis
force-pull: true
default-label: master
repos:
project1:
pattern: project1-*
cloneOnStart: true
uri: http://gitlab.ugirls.com:9999/project1.git
project2:
pattern: project2-*
cloneOnStart: true
uri: http://gitlab.ugirls.com:9999/project2.git
as my project has some common configuration file, so I put it to commonconfig.git.
commonconfig.git contains datasource-dev.properties, datasource-prod.properties
project1.git contains application-dev.yml, application-prod.yml
up till now, it looks like ok, visit http://localhost:8411/project1-application.xml that's ok
{
name: "project1-application",
profiles: [
"dev"
],
label: "master",
version: "978c1dc67a6bb6672b7e7ae7620f2c5794897a31",
state: null,
propertySources: [
{
name: "http://gitlab.ugirls.com:9999/project1.git/application-dev.yml",
}...
and visit http://localhost:8411/datasource/dev still ok.
But.... my config client project: the bootstrap.yml like as flows:
spring:
application:
name: project1-application
cloud:
config:
label: master
profile: ${spring.profiles.active}
uri: http://localhost:8411/
name: project1-application,datasource
it only read application-dev.yml but not datasource.properties the log like this:
Located environment: name=project1-application, profiles=[dev], label=master, version=978c1dc67a6bb6672b7e7ae7620f2c5794897a31, state=null
2018-01-26 13:54:26.613 INFO [datasource,redis_chat,redis_main,redis_rank,,,] 6064 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='http://gitlab.ugirls.com:9999/project1.git/application-dev.yml'}, MapPropertySource {name='http://gitlab.ugirls.com:9999/project1.git/application.yml'}]]
Once I changed spring.cloud.config.name=datasource
it will be only load datasource-dev.properties
could any one can explain it, or give me some advice? thanks
Upvotes: 1
Views: 1759
Reputation: 649
Spring cloud config server now supports a "composite repo" setup that would allow you to add your repo that contains shared properties.
See the documentation here.
For you, this would be something like:
spring:
profiles:
active: composite
cloud:
config:
server:
composite:
-
type: git
# Default URI is required to be present, even if not used
uri: blahblah
repos:
project1:
pattern: project1-*
cloneOnStart: true
uri: http://gitlab.ugirls.com:9999/project1.git
project2:
pattern: project2-*
cloneOnStart: true
uri: http://gitlab.ugirls.com:9999/project2.git
-
type: git
uri: http://gitlab.ugirls.com:9999/commonconfig.git
search-paths: db,redis
Upvotes: 0