title: Can @PropertySources be chosen by Spring profile?
body: <p>I have a Spring 3.1 <code>@Configuration</code> that needs a property <code>foo</code> to build a bean. The property is  defined in <code>defaults.properties</code> but may be overridden by the property in <code>overrides.properties</code> if the application has an active <code>override</code> Spring profile.</p>
  
  <p>Without the override, the code would look like this, and work...</p>
  
  <pre><code>@Configuration
  @PropertySource("classpath:defaults.properties")
  public class MyConfiguration {
  
      @Autowired
      private Environment environment;
  
      @Bean
      public Bean bean() {
          ...
          // this.environment.getRequiredProperty("foo");
          ...
      }
  }
  </code></pre>
  
  <p>I would like a <code>@PropertySource</code> for <code>classpath:overrides.properties</code> contingent on <code>@Profile("overrides")</code>. Does anyone have any ideas on how this could be achieved? Some options I've considered are a duplicate <code>@Configuration</code>, but that would violate DRY, or programmatic manipulation of the <code>ConfigurableEnvironment</code>, but I'm not sure where the <code>environment.getPropertySources.addFirst()</code> call would go.</p>
  
  <p>Placing the following in an XML configuration works if I inject the property directly with <code>@Value</code>, but not when I use <code>Environment</code> and the <code>getRequiredProperty()</code> method.</p>
  
  <pre><code>&lt;context:property-placeholder ignore-unresolvable="true" location="classpath:defaults.properties"/&gt;
  
  &lt;beans profile="overrides"&gt;
      &lt;context:property-placeholder ignore-unresolvable="true" order="0"
                                    location="classpath:overrides.properties"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>If you're trying to do this now, check out Spring Boot's <a href="http://projects.spring.io/spring-boot/docs/spring-boot/README.html" rel="noreferrer">YAML support</a>, particularly the 'Using YAML instead of Properties' section. The profile support there would make this question moot, but there isn't <code>@PropertySource</code> support yet.</p>