title: Correctly using Spring environment profiles in order to manage PropertySourcesPlaceholderConfigurer and sets of properties files
body: <p>I am working on a Spring application and I am realizing that I have an issue with the way I manage my properties. <strong>I use Spring environment profiles in order to load my properties and I've recently added more profiles which has made my properties files unmanagable</strong>.</p>
  
  <p>The properties files are located in different folders within <code>src/main/resources/META-INF/props/</code>, with eah folder matching a different Spring environment profile. </p>
  
  <p>I have at least 5 profiles now which means I have 5 sub-folders each containing the properties files with the same names but <strong>with different values for only some keys</strong>.</p>
  
  <p>Here is how it looks:</p>
  
  <p><img src="https://i.stack.imgur.com/KzIcF.png" alt="properties file screen capture"></p>
  
  <p>Here is how I've configured my PropertyPlaceholders:</p>
  
  <pre><code>@Configuration
  public class PropertyPlaceholderConfiguration {
  
      @Profile(Profiles.CLOUD)
      static class cloudConfiguration {
          @Bean
          public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
              PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
              propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
              propertySourcesPlaceholderConfigurer.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:META-INF/props/cloud/*.properties"));
              return propertySourcesPlaceholderConfigurer;
          }
      }
  
      @Profile(Profiles.DEFAULT)
      static class defaultConfiguration {
          @Bean
          public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
              PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
              propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
              propertySourcesPlaceholderConfigurer.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:META-INF/props/default/*.properties"));
              return propertySourcesPlaceholderConfigurer;
          }
      }
  
      @Profile(Profiles.TEST)
      static class testConfiguration {
          @Bean
          public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
              PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
              propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
              propertySourcesPlaceholderConfigurer.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:META-INF/props/test/*.properties"));
              return propertySourcesPlaceholderConfigurer;
          }
      }
  
      @Profile(Profiles.DEV)
      static class devConfiguration {
          @Bean
          public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws IOException {
              PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
              propertySourcesPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
              propertySourcesPlaceholderConfigurer.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:META-INF/props/dev/*.properties"));
              return propertySourcesPlaceholderConfigurer;
          }
       ...
      }
  </code></pre>
  
  <p>To sum up, my problem is as follows:</p>
  
  <ul>
  <li>key/value pairs are duplicated all over the 5 different folders because only a few values are different. </li>
  </ul>
  
  <p>I am therefore looking for a new strategy to manage the differences between the different environments. </p>
  
  <p>Can anyone please help?</p>