Spring PropertySourcesPlaceholderConfigurer and Environment
<p>I want to configure properties for different profiles (production and dev).</p>

<p>That's my configuration:</p>

<pre><code>@Configuration
public class PropertyPlaceholderConfig {

  @Profile(Profiles.PRODUCTION)
  static class ProductionConfiguration {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigure()
    throws IOException {
      PropertySourcesPlaceholderConfigurer propertySources =
      new PropertySourcesPlaceholderConfigurer();
      propertySources.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
      Resource[] resources =
      ObjectArrays.concat(getCommonResources(), getProductionResources(), Resource.class);
      propertySources.setLocations(resources);
      return propertySources;
    }

    private static Resource[] getProductionResources() throws IOException {
      return new PathMatchingResourcePatternResolver()
      .getResources("classpath:properties/production/*.properties");
    }

  }


  @Profile(Profiles.DEV)
  static class DevConfiguration {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigure()
    throws IOException {
      PropertySourcesPlaceholderConfigurer propertySources =
      new PropertySourcesPlaceholderConfigurer();
      propertySources.setIgnoreUnresolvablePlaceholders(Boolean.TRUE);
      Resource[] resources =
      ObjectArrays.concat(getCommonResources(), getDevResources(), Resource.class);
      propertySources.setLocations(resources);
      return propertySources;
    }

    private static Resource[] getDevResources() throws IOException {
      return new PathMatchingResourcePatternResolver()
      .getResources("classpath:properties/dev/*.properties");
    }

  }


  private static Resource[] getCommonResources() throws IOException {
    return new PathMatchingResourcePatternResolver()
    .getResources("classpath:properties/common/*.properties");
  }


}
</code></pre>

<p>I printed current profile (dev) and loaded files (all have been correcly loaded into Resouce array). I want to use this loaded properties in database config. How to do it?
I used:</p>

<pre><code>@Import(PropertyPlaceholderConfig.class)
</code></pre>

<p>over the class,
and:</p>

<pre><code>@Autowired
private Environment environment;
</code></pre>

<p>but</p>

<pre><code>environment.getProperty("h2.driverClass");
</code></pre>

<p>or</p>

<pre><code>environment.resolvePlaceholders("${h2.driverClass}");
</code></pre>

<p>doesn't work.</p>

<p>How to use properties loaded by PropertySourcesPlaceholderConfigurer?</p>

<p>I know that I can use @Value with fields but is it possible to avoid creating 15 fields?</p>