title: Properties Placeholder Inheritance in Spring 3.1
body: <p>I'm trying to port our Custom Properties Placeholder with Spring's new <code>Environment</code> support but I can't figure out how to get what our current placeholder magic does.</p>
  
  <p>What I would like is for a default bunch of property files to be read from classpath and then have those properties overridden (overlay) by a bunch of properties files from somewhere else. <strong>I don't want all of the properties replaced just the ones that are set in the other group of files.</strong></p>
  
  <p><strong>Prior to Spring 3.1</strong></p>
  
  <pre><code>&lt;bean class="com.snaphop.spring.ConfigResourcesFactoryBean" id="customConfig"&gt;
      &lt;property name="parameterName" value="customConfig"/&gt;
      &lt;property name="defaultResources" value="classpath*:META-INF/spring/*.properties"/&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" id="customPropertyPlaceholder"&gt;
      &lt;property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/&gt;
      &lt;property name="locations" ref="customConfig"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now ConfigResourcesFactoryBean is just a magically FactoryBean that finds the list of resources to feed to the placeholder config:</p>
  
  <pre><code>public class ConfigResourcesFactoryBean implements FactoryBean&lt;Resource[]&gt; {
  // Loads a bunch of Resources (property files) 
  // based on System.property/Environment variable "customConfig"
  }
  </code></pre>
  
  <p>Now customConfig might be set like <code>-DcustomConfig=file://blah/*.properties</code> or <code>export customConfig=file://blah/*.properties</code>.</p>
  
  <p>The properties in the directory <code>blah</code> only override a subset of the <code>classpath*:META-INF/spring/*.properties</code>. Thus the returned <code>Resource[]</code> from the factory will be a union of <code>classpath*:META-INF/spring*.properties</code> followed by <code>file://blah/*.properties</code> respectively.</p>
  
  <p>Now it appears instead of my <code>Resource[]</code> factory I can make a custom <code>PropertySources</code> and wire that into the PlaceholderConfig but that seems like it offers no value then the above.</p>
  
  <p>I cannot use <a href="http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/context/ApplicationContextInitializer.html" rel="nofollow"><code>ApplicationContextInitializer</code></a> because I swear that only works with Servlet environments and thus will not work with integration tests (I don't feel like adding an annotation on every single one of my unit tests to go tell it what the environment is when I could just set a system property like I did before).</p>
  
  <p><strong>How does one overlay properties from hardcoded sources with custom sources with out having  to overriding/implementing a bunch of classes?</strong></p>