title: Spring 4 Properties annotation
body: <p>I am trying to use spring 4 too load properties and use them in the classes, but it I can't get it to work. This is not an MVC appication and the reported duplicatet does not give me any clue on my issue.  Here is what I got in my test project:</p>
  
  <p>The main class:</p>
  
  <pre><code> public class Main {
  
      public static void main(String...args) {
          ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
          Tester t = new Tester();
          t.testBean();
      }
  }
  </code></pre>
  
  <p>ApplicationConfig Class:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages={"nl.foo.propertiestest"})
  @PropertySource("application.properties")
  public class ApplicationConfig {
  //Spring framework will know what to do with this class
  
      @Bean
      public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
          return new PropertySourcesPlaceholderConfigurer();
      }
  }
  </code></pre>
  
  <p>The Tester Ckass:</p>
  
  <pre><code>public class Tester {
      @Autowired
      Environment env;
  
       @Bean
       public void testBean() {
           System.out.println("testBean start");
           String a = env.getProperty("test");
           System.out.println("property = " + a);
           System.out.println("testBean e");
       }
  
  }
  </code></pre>
  
  <p>The application.properties:</p>
  
  <pre><code>test=hello tester
  </code></pre>
  
  <p>The application gives a null pointer exception on <code>tring a = env.getProperty("test");</code> but it seems to load the properties, as it gives an error when the properties file is not in the class path.</p>
  
  <p>How do I get the property retrieved?</p>