title: Using properties defined by <context:property-placeholder> in a factory method
body: <p>I have written a factory bean that creates a cache manager based on the properties that are configured in a application specific properties file.</p>
  
  <p>The concept is that multiple implementations can be chosen, each using other configuration properties. </p>
  
  <p>For example:</p>
  
  <ul>
  <li>noop cache, without parameters,</li>
  <li>ehcache with #max objects</li>
  <li>memcache with multiple ips and ports configured.</li>
  </ul>
  
  <p>I think it is nice to not specify all cache-application specific parameters in the <code>application-context.xml</code>, but read them from the existing properties sources. </p>
  
  <p>My attempt was using a <code>EnvironementAware</code> interface to get access to the <code>Environement</code>. But it  seems that the property file that is configured using <code>&lt;context:property-placeholder&gt;</code> is not contained in the <code>PropertiesSources</code>.</p>
  
  <p>example.properties</p>
  
  <pre><code>cache.implementation=memcached
  cache.memcached.servers=server1:11211,server2:11211
  </code></pre>
  
  <p>application-context.xml</p>
  
  <pre><code>&lt;context:property-placeholder location="example.properties"/&gt;
  &lt;bean id="cacheManager" class="com.example.CacheManagerFactory"/&gt;
  </code></pre>
  
  <p>In CacheManagerFactory.java</p>
  
  <pre><code>public class CacheManagerFactory implements FactoryBean&lt;CacheManager&gt;, EnvironmentAware {
  
      private Environement env;
  
      @Override
      public CacheManager getObject() throws Exception {
          String impl = env.getRequiredProperty("cache.implementation"); // this fails
      //Do something based on impl, which requires more properties.
      }
  
      @Override
      public void setEnvironment(Environment env) {
          this.env = env;
      }
  
      @Override
      public Class&lt;?&gt; getObjectType() {
          return CacheManager.class;
      }
  
      @Override
      public boolean isSingleton() {
          return true;
      }
  
  }
  </code></pre>