Describe the bug I have Config Server with File System Backend for several microservices. It contains hierarchy yaml resources with default(for all) and ms specific properties.
Spring Boot 2.7.6 Cloud 2021.0.5 ( Config Server 3.1.5)
config/
---application.yml
---microservice-one.yml
Both resources contains default and profile specific property. application.yml
value: value-for-profile-override
all-value: value-for-all-ms
---
spring:
config:
activate:
on-profile: dev
value: value-dev
dev-all-ms-value: value-dev-for-all-ms
---
spring:
config:
activate:
on-profile: prod
value: value-prod
dev-all-ms-value: value-prod-for-all-ms
microservice-one.yml
one-value: ms-one-all-profile-value
---
spring:
config:
activate:
on-profile: dev
dev-one-value: ms-one-dev-profile-value
---
spring:
config:
activate:
on-profile: prod
dev-one-value: ms-one-prod-profile-value
I try to read config with profile 'dev' for my ms. Both property sources is returned, but application.yml contains only profile depend part.
curl http://localhost:8888/microservice-one/dev
{
"name": "microservice-one",
"profiles": [
"dev"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "Config resource 'class path resource [config/microservice-one.yml]' via location 'optional:classpath:/config/' (document #1)",
"source": {
"spring.config.activate.on-profile": "dev",
"dev-one-value": "ms-one-dev-profile-value"
}
},
{
"name": "Config resource 'class path resource [config/microservice-one.yml]' via location 'optional:classpath:/config/' (document #0)",
"source": {
"one-value": "ms-one-all-profile-value"
}
},
{
"name": "Config resource 'class path resource [config/application.yml]' via location 'optional:classpath:/config/' (document #1)",
"source": {
"spring.config.activate.on-profile": "dev",
"value": "value-dev",
"dev-all-ms-value": "value-dev-for-all-ms"
}
}
]
}
Response missed part with "all-value: value-for-all-ms" property. But contains same 'profile independet' part from microservice-one.yml
I have an bug demo project to reproduce the problem/
This behavior worked fine on 2.2.6 version of CFS.
Comment From: ryanjbaxter
When you say it worked fine in 2.2.6 version of CFS
, is that Spring Boot 2.2.6, or Spring Cloud Config 2.2.6?
Comment From: Murik
on Spring Cloud Config 2.2.6 it work, but only in docker environment. we used docker config server before update.
Cloud Hoxton.SR9 Boot 2.3.2.RELEASE
but i could not reproduce it on clean repository branch with 2.2.6. :) only in docker.
after a little debugging. i found that "applicationConfig: [classpath:/config/application.yml] (document #0)" contains in environment.getPropertySources() So, this part is ignored in org.springframework.cloud.config.server.environment.NativeEnvironmentRepository#clean by block
String name = source.getName();
if (this.environment.getPropertySources().contains(name)) {
continue;
}
in docker env environment.getPropertySources() contains "applicationConfig: [classpath:./config/application.yml] (document #0)" so it not the same that in name variable - "applicationConfig: [classpath:/config/application.yml] (document #0)" because of a dot in a path.. and in this case all works as i expected.
in new docker env environment.getPropertySources() now contains "Config resource 'file [/config/application.yml]' via location 'optional:file:/config/' (document #0)" and name is also "Config resource 'file [/config/application.yml]' via location 'optional:file:/config/' (document #0)" so this part is skipped.
now i don't sure that it is a bug. :) it is not intuitive to skip base part of config/application.yml anyway imho.
Now I fixed this problem by rename directory to "props" and add spring.cloud.config.server.native.searchLocations=props property.