title: Creating hierarchical properties files with spring boot
body: <p>We have a project that contains three resources files - <code>application-dev.properties</code> <code>application-test.properties</code> and <code>application-prod.properties</code>. We have an environment variable that sets the name of the environment we're in and then we load the right property file using computed placeholder as followed:</p>
  
  <pre><code>@Configuration
  @PropertySource("classpath:application-${environment}.properties")
  public class ApplicationConfiguration {
  
  }
  </code></pre>
  
  <p>I wish to add a new file <code>application-defaults.properties</code> that will have all the default properties and only proerties that appear in <code>application-${environment}.properties</code> would be overrided by the specific environment property. I tried to do it as follows:</p>
  
  <pre><code>@Configuration
  @PropertySource({"classpath:application-defaults.properties", "classpath:application-${environment}.properties"})
  public class ApplicationConfiguration {
  
  }
  </code></pre>
  
  <p>Thing is, the properties from the defaults file always "win" and take precedence while I want them to be overridden in case the property appears in the specified environment variable. I tried switching the order between them, but still it stays the same. I even tried to change the name of the defaults file to <code>default.properties</code> just in order to understand whether the loading order is lexicographic or something like that, but still - the <code>default.properties</code> always win.</p>
  
  <p>Note: In order to load the app we use spring-boot.</p>