title: @Value works without configuring static PropertySourcesPlaceholderConfigurer
body: <p>I am trying to understand the behaviour of @PropertySource annotation when not using @Autowiring and Spring Environment class. I am trying to use @Value to inject values from a properties file at runtime. From the book that I am reading and from the online sources it is required to have a static bean - PropertySourcesPlaceholderConfigurer configured in order for this to work. But for me the @Value works without PropertySourcesPlaceholderConfigurer static bean as well. Can someone point me to the right direction as to whats happening here. May be I am missing something very basic. When do we need PropertySourcesPlaceholderConfigurer and when not?</p>
  
  <p>Below is the code that I am trying out - </p>
  
  <pre><code>package com.nilaysundarkar.demos;
  
  public class Person {
  
      private String name;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  }
  </code></pre>
  
  <p>AppConfig.java - </p>
  
  <pre><code>package com.nilaysundarkar.demos;
  
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
  
  @Configuration
  @PropertySource("classpath:/com/nilaysundarkar/demos/app.properties")
  public class AppConfig {
  
      // This bean does not make any difference, or does it?
      /*@Bean
      public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer(){
          return new PropertySourcesPlaceholderConfigurer();
      }*/
  
      @Bean
      public Person person(@Value("${person.name}") String name){
          Person person = new Person();
          person.setName(name);
          return person;
      }
  
  }
  </code></pre>
  
  <p>Bootstrap - </p>
  
  <pre><code>package com.nilaysundarkar.demos;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  
  public class App {
  
      public static void main(String[] args){
  
          ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
          Person person = context.getBean(Person.class);
          System.out.println(person.getName());
          ((AnnotationConfigApplicationContext)context).close();
      }
  
  }
  </code></pre>
  
  <p>properties file - app.properties - </p>
  
  <pre><code>person.name=John Doe
  </code></pre>
  
  <p>pom - </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.nilaysundarkar.demos&lt;/groupId&gt;
  &lt;artifactId&gt;demos-runtime-injections&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;4.3.7.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;4.3.7.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
          &lt;version&gt;4.3.7.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
          &lt;version&gt;4.0.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.11&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p></p>
  
  <p>When I run App.java - </p>
  
  <p><a href="https://i.stack.imgur.com/ExKoa.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ExKoa.png" alt="enter image description here"></a></p>