title: Resolving placeholder within @PropertySource
body: <p>I'm trying to make a configuration class that will load application properties from a file using the @PropertySource annotation, but the PropertySourcesPlaceholderConfigurer doesnt seem to set the location received from the annotation.</p>
  
  <pre><code>@Configuration
  @ComponentScan("com.just.a.test")
  @PropertySources({
      @PropertySource(value="file:C:\\tmp\\1.cfg" 
              , ignoreResourceNotFound=true)
  })
  public class TestConfig {
      @Value("${just.a.string}")
      String justAString;
  
  
      @Bean
      public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
          PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
         return propertySourcesPlaceholderConfigurer;
      }
  }
  </code></pre>
  
  <p>the application property file is :</p>
  
  <pre><code>just.a.string=DOH
  </code></pre>
  
  <p>and im receiving the following exception :</p>
  
  <blockquote>
    <p>....
        Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'just.a.string' in string value "${just.a.string}"<br/>
            at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)<br/>
            at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)<br/>
            at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204)<br/>
            at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178)<br/>
            at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175)<br/>
            at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:801)<br/>
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:955)<br/>
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)<br/>
            at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)<br/>
            ... 15 more</p>
  </blockquote>
  
  <p>how ever, if i am setting the location using the PropertySourcesPlaceholderConfigurer bean, everything works fine.</p>
  
  <pre><code>@Bean
      public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
          PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
  propertySourcesPlaceholderConfigurer.setLocation(new FileSystemResource("c:\\tmp\\1.cfg"));
         return propertySourcesPlaceholderConfigurer;
      }
  </code></pre>
  
  <p>i am using Spring 4.1.6-RELEASE , and jdk 8.05.</p>
  
  <p>thanks in advance.</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>as sivaprasadreddy.k mentioned. the code above does work fine, i forgot that in my original code i am retrieving the file out of a JVM param using the - </p>
  
  <pre><code>@PropertySource(value="file:#{systemProperties['config.path']}" 
  </code></pre>
  
  <p>and passing a jvm param of:</p>
  
  <pre><code>-Dconfig.path=C:\\tmp\\1.cfg
  </code></pre>
  
  <p>@Sotirios - im just using an AnnotationConfigApplicationContext(Class) like so - </p>
  
  <pre><code>public static void main(String[] args) { 
  new AnnotationConfigApplicationContext(TestConfig.class);
   }
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>basically what im trying to achieve is this:</p>
  
  <p>1) load a property file using a jvm param which its name defined as a const</p>
  
  <p>a) if the file is found then proceed</p>
  
  <p>b) else if a default file path which defined as a const exists then proceed</p>
  
  <p>c) else proceed.</p>
  
  <p>2) try to resolve @Value using a property which its name is defined as a const</p>
  
  <p>a) if found proceed</p>
  
  <p>b) else load a default value using a const.</p>
  
  <p>sorry for the spaces. something is wrong with the editor.</p>