Spring @Autowired bean not initialising; Null Pointer Exception
<p>Target.java:</p>

<pre><code>package me;

@Component
public class Target implements Runnable {   
    @Autowired
    private Properties properties;

    public Target(){
        properties.getProperty('my.property');
    }

    public void run() {
        //do stuff
    }
}
</code></pre>

<p>Config.java:</p>

<pre><code>@Configuration
@ComponentScan(basePackages = {"me"})
public class Config {
    @Bean(name="properties")
    public PropertiesFactoryBean properties() {
        PropertiesFactoryBean bean = new PropertiesFactoryBean();
        bean.setLocation(new FileSystemResource("src/my.properties"));
        return bean;
    }

    public static void main(String[] argv) throws Exception {
        ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
        Target t = context.getBean(Target.class);
        t.run();
    }
}
</code></pre>

<p>With the above code. Bottom of stack:</p>

<pre><code>Caused by: java.lang.NullPointerException
 at me.Target.&lt;init&gt;(Target.java:9)
 ....
</code></pre>