title: Spring not loading properties
body: <p>Spring not loading properties when applicationContext.xml is referenced in a @Configuration class </p>
  
  <pre><code>@Configuration
  @ImportResource("classpath:applicationContext.xml")
  public class SpringConfig {
  
    @Autowired
      private MyBean1 myBean1;
  
    @Bean
      public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
          return new PropertySourcesPlaceholderConfigurer();
  
      }
  
    @Bean(name = "myBean2")
      public MyBean2 myBean2() {
      MyBean2 bean2 = new MyBean2();
      return bean2;
      }
  
  
  }
  </code></pre>
  
  <p><strong>applicationContext.xml:</strong></p>
  
  <pre><code>&lt;bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
         &lt;property name="location"&gt;           
                  &lt;value&gt;classpath:test.properties&lt;/value&gt;           
          &lt;/property&gt;
      &lt;/bean&gt;
  
    &lt;bean id="myBean1" class="com.foo.bar.MyBean1"&gt;
          &lt;property name="name" value="${name}" /&gt;  
          &lt;property name="age" value="${age}" /&gt;  
      &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Test.properties:</strong> (in the classpath)</p>
  
  <pre><code>name=foo
  age=10
  </code></pre>
  
  <p>When I load the applicationContext.xml file using the following lines of code, it worked:</p>
  
  <pre><code>ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
  </code></pre>
  
  <p>I see the following lines printed:</p>
  
  <pre><code>2015-05-30 10:01:08.277 [INFO] org.springframework.beans.factory.config.PropertyPlaceholderConfigurer:172 - Loading properties file from class path resource [test.properties]
  2015-05-30 10:01:08.292 [INFO] org.springframework.beans.factory.support.DefaultListableBeanFactory:596 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5c001eb0: defining beans [placeholderConfig,myBean1]; root of factory hierarchy
  </code></pre>
  
  <p>I have no issues loading the test.properties file with "myBean1" getting the value of ${name} and {age} from the properties file.</p>
  
  <p>The issue I have is when I try to load SpringConfig:</p>
  
  <pre><code>ApplicationContext ctx =   new AnnotationConfigApplicationContext(SpringConfig.class);
  </code></pre>
  
  <p>The SpringConfig class refers to applicationContext.xml as: @ImportResource("classpath:applicationContext.xml")</p>
  
  <p>The error I am seeing is:</p>
  
  <pre><code>org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'myBean1' defined in class path resource [applicationContext.xml]: Could not resolve placeholder 'name' in string value "${name}"
                              at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
                              at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:174)
                              at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)
                              at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
                              at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
                              at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
                              at org.springframework.context.annotation.AnnotationConfigApplicationContext.&lt;init&gt;(AnnotationConfigApplicationContext.java:73)
  </code></pre>
  
  <p>In a nutshell, when I load applicationContext using ClassPathXmlApplicationContext, then I have no issue:</p>
  
  <p><strong>Working:</strong></p>
  
  <p>ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");</p>
  
  <p>But when it is referred by SpringConfig, then I see that applicationContext does not see my properties file.</p>
  
  <p><strong>Not Working:</strong></p>
  
  <p>ApplicationContext ctx =   new AnnotationConfigApplicationContext(SpringConfig.class);</p>
  
  <p>Please note that test.properties is in my classpath and it is nothing to do with the properties file missing or something.</p>
  
  <p>I don't know if I have to use a different approach for AnnotationConfigApplicationContext as I need myBean1 to be auto-wired into SpringConfig and myBean1 uses some properties from the test.properties file.</p>