spring-cloud / spring-cloud/spring-cloud-config
Document property source precendence using spring.config.import defined in application.yml vs adding as -Dspring.config.import
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2k
- Forks
- 1.3k
- Avg merge
- 2d 59m
- Merged PRs (30d)
- 16
Description
Describe the bug
When we add spring.config.import in application.yml of an application's src/main/resources vs the same property is added as -D parameter during the start up of the application, the behavior changes in terms of property order.
Sample
A test case is added namely ServerMyTestApplicationTests under spring-cloud-config/spring-cloud-config-sample/src/test/java (https://github.com/nagsuchandra/spring-cloud-config.git) and it's method contextLoads shows the issue. There is documentation added to the source file .
Error case:
application.yml has the following
spring:
cloud:
config:
uri: http://localhost:${config.port:8888}
config:
import: configserver:${spring.cloud.config.uri}
Now if we run the test ServerMyTestApplicationTests.contextLoads, the property sources are as follows.
- Config resource 'class path resource [application-baz.yml]' via location 'optional:classpath:/':{key=jarlocal-app-baz-yml}
- configserver:file:././target/repos/configmytest-repo//payroll-baz.yml:{key=remote-payroll-baz-yml}
- configserver:file:././target/repos/configmytest-repo//application-baz.yml:{key=remote-app-baz-yml}
- configserver:file:././target/repos/configmytest-repo//payroll.yml:{key=remote-payroll-yml}
- configserver:file:././target/repos/configmytest-repo//application.yml:{info.foo=bar}
- Config resource 'class path resource [application.yml]' via location 'optional:classpath:/':{info.component=Config Samples, endpoints.restart.enabled=true, logging.levels.org.springframework.boot.env.PropertySourcesLoader=TRACE, logging.levels.org.springframework.web=DEBUG, spring.cloud.config.uri=http://localhost:${config.port:8888}, spring.config.import=configserver:${spring.cloud.config.uri}}
application.yml does NOT have the spring.config.import in there and -Dspring.config.import is passed in
- configserver:file:././target/repos/configmytest-repo//payroll-baz.yml:{key=remote-payroll-baz-yml}
- configserver:file:././target/repos/configmytest-repo//application-baz.yml:{key=remote-app-baz-yml}
- configserver:file:././target/repos/configmytest-repo//payroll.yml:{key=remote-payroll-yml}
- configserver:file:././target/repos/configmytest-repo//application.yml:{info.foo=bar}
- Config resource 'class path resource [application-baz.yml]' via location 'optional:classpath:/':{key=jarlocal-app-baz-yml}
- Config resource 'class path resource [application.yml]' via location 'optional:classpath:/':{info.component=Config Samples, endpoints.restart.enabled=true, logging.levels.org.springframework.boot.env.PropertySourcesLoader=TRACE, logging.levels.org.springframework.web=DEBUG}
Config data files ordering gets reversed if application.yml has spring.config.import defined in it , but -D maintains the ordering in the right precedence.
- Application properties packaged inside your jar (application.properties and YAML variants).
- Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).
- Application properties outside of your packaged jar (application.properties and YAML variants).
- Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants). – highest priority
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with spring-cloud-config-sample/src/test/java/ServerMyTestApplicationTests and its contextLoads method, then compare the application.yml and -Dspring.config.import cases described in the issue. Review the documented property-source ordering and update the relevant source-file documentation so the differing precedence is explained and the example accurately reflects the observed behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- backend, documentation, testing
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 39/100