Search code examples
propertiesoperator-precedencespring-cloud-config

Spring cloud config precedence property files


Trying to read about the precedence of loading several properties in Spring cloud config, I am not finding my case to figure it out which is the precedence of properties. My case is the next:

I have the next properties in the spring cloud config application:

  • application.properties
  • application-dev.properties
  • nameOfApplicationXX.properties
  • nameOfApplicationXX-dev.properties

I am launching the app nameOfApplicationXX with the dev profile. My case is that application-dev.properties has one property and this property is not being overriden by the same property present in nameOfApplication.properties. So, application-dev.properties has preference over nameOfApplicationXX.properties because the first one is specifying a profile?

Which is the precedence of each one? Do you know the docs reference because I am not finding it

Thanks


Solution

  • If I understood your problem correctly then the below is the solution I have found from the Spring Cloud Config document reference: "If the repository is file-based, the server creates an Environment from application.yml (shared between all clients) and foo.yml (with foo.yml taking precedence). If the YAML files have documents inside them that point to Spring profiles, those are applied with higher precedence (in order of the profiles listed). If there are profile-specific YAML (or properties) files, these are also applied with higher precedence than the defaults. Higher precedence translates to a PropertySource listed earlier in the Environment. (These same rules apply in a standalone Spring Boot application.)"

    Spring Cloud Config reference link : Documentation

    Note: By seeing the above problem statement I can say that you are using file based profile in Spring cloud Config server. The Spring Cloud Config server will return List of Property Sources for each type as a classpath resource properties.

    To override the the default implementation I have implemented the same and reference code is available in gitHub link : Source Code

    Not a similar issue but may help you : reference issue

    Hope this will help you to fix the above mentioned problem statement.