Spring cloud version : Finchley.SR2 Spring boot version : 2.0.6.RELEASE

spring cloud config with jdbc backend does not return the property sources in correct order.

Consider following configuration

application.yml key1 : val1 spring.profile: test key2: val2

service.yml key3: val3 spring.profile: test key2:val2

With native or git backend if i try to fetch properties with profile test then the order of property source is 1. service.yml - profile test 2. application.yml - profile test 3. service.yml - profile default 4. application.yml - profile default

But if i use jdbc as backend then format of returned property source is 1. service.yml - profile test 2. service.yml - profile default 3. application.yml - profile test 4. application.yml - profile default

What it does is when service is started it does not receive correct set of properties.

After looking at code in JdbcEnvironmentRepository, if the following for loop are switched (i.e loop through env and then application) it should fix the problem for (String app : applications) { for (String env : envs) { } }

Comment From: TYsewyn

Can you please try with the latest service release of Spring Boot (2.0.9.RELEASE) and Spring Cloud (Finchley.SR4). Please keep in mind that Spring Boot 2.0.x will soon be EOL so we strongly encourage you to upgrade to Spring Boot 2.1 and Spring Cloud Greenwich.

Comment From: VikramAhuja

I have tried with Spring Boot (2.0.9.RELEASE) and Spring Cloud (Finchley.SR4) and still it does not work. I have attached sample project for your reference. you can run the test cases and see order is different when config server is backed by jdbc and files system.

jdbc-bug.zip

Comment From: TYsewyn

Thank you for the example! We are happy to accept your PR if you want :)

Comment From: VikramAhuja

I am ready with the my fix but i can not push my branch as i dont have permission to do so i get following error Pushing to https://github.com/spring-cloud/spring-cloud-config.git remote: Permission to spring-cloud/spring-cloud-config.git denied to VikramAhuja. fatal: unable to access 'https://github.com/spring-cloud/spring-cloud-config.git/': The requested URL returned error: 403

Can you give me permission to push my branch.

Comment From: spencergibb

I'm not sure there is a problem with the order.

Also you have to fork the project and create a pull request, we're can't give you permission to push directly to this project

Comment From: VikramAhuja

In my previous comment i have attached sample project which shows order of property sources in jdbc and file system is different.

Ok i will fork the project and create a pull request.

Comment From: spencergibb

The order you listed for the jdbc sources is correct. With the first list you use spring.profile to alter the order from the default.

Comment From: VikramAhuja

i have used spring.profile for both the case when back end is jdbc and file system both return property source in different order. what you mean by to alter the order i have used spring profile, input data is same for both the system.

Comment From: spencergibb

Flagging for team discussion.

Comment From: ashirley

This is still an issue in master and regardless of which order is correct, surely JdbcEnvironmentRepository1 and NativeEnvironmentRepository2 should be consistent with each other.

Comment From: spencergibb

PR #1436

Comment From: ryanjbaxter

This appears to be fixed in 2021.0.1 from what I can see, both native and jdbc environment repositories come back with the same order using the example provided

Native

{
"name": "service",
"profiles": [
"test"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "Config resource 'file [config/service.yml]' via location 'optional:file:./config/' (document #1)",
"source": {
"spring.profiles": "test",
"key2": "value22"
}
},
{
"name": "Config resource 'file [config/service.yml]' via location 'optional:file:./config/' (document #0)",
"source": {
"key3": "value3"
}
},
{
"name": "Config resource 'file [config/application.yml]' via location 'optional:file:./config/' (document #1)",
"source": {
"spring.profiles": "test",
"key2": "value2"
}
}
]
}

JDBC

{
"name": "service",
"profiles": [
"test"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "service-test",
"source": {
"key2": "value22"
}
},
{
"name": "service-default",
"source": {
"key3": "value3"
}
},
{
"name": "application-test",
"source": {
"key2": "value2"
}
},
{
"name": "application-default",
"source": {
"key1": "value1"
}
}
]
}