Loading Precedence of Application.yml, Bootstrap.yml and VM Arguments in Spring Cloud
2 min readOct 23, 2021
When you work with microservices, you will work with different property loading sources. Knowing loading precedence of the sources are very important. In this post, i will try to explain the precedence process for different sources.
I have six sources for loading values as below;
My test class and the result that is in console are as below;
We can say;
- servicename-profile.yml files have the highest priority. Because, ‘a’ is present in all files, but the value(5) in test-service-dev.yml file was read.
- servicename.yml files(like test-service.yml) which don’t have “-profile” suffix are ignored. Because, The value ‘b’(3) in application-dev.yml was read instead of the value ‘b’(4) in test-service.yml. instead
- application.yml files have lower priority than application-profile.yml files(like application-dev.yml). Because, The value ‘c(3)’ in application-dev.yml was read instead of the value ‘c(2)’ in application.yml.
- VM arguments has lower priority than application.yml. Because, The value ‘d(2)’ in application.yml was read instead of the value ‘d(1)’ in VM arguments.
- VM arguments has higher priority than bootstrap.yml Because, The value ‘e(0)’ in VM arguments was read instead of the value ‘e(1)’ in bootstrap.yml file. But; when you have values as below, you will see servicename.yml files(like test-service.yml) is higher priority than VM arguments and bootstrap.yml file.
- bootstrap.yml has lowest priority. When you don’t have any source, your values in bootstrap is valid (like the value ‘g(1)’ in bootstrap.yml file)
Summary
Order of precedence is servicename-profile.yml > appication-profile.yml > application.yml > servicename.yml > VM arguments > bootstrap.yml