autowired component is null
<p>I'm developing a web application with spring. I've had no problem autowiring and using database @Service classes. Now I'm trying to read a global property file and provide the values to all classes that need them. The solution I've come up with so far seem to be overly complicated (too many classes - AppConfig, ServerConfig iface, ElasticServerConfig) for such a trivial task but I could live with it if it worked.</p>

<p>my applicationContext.xml contains</p>

<pre><code>&lt;context:component-scan base-package="my.package" /&gt;
</code></pre>

<p>AppConfig.java:</p>

<pre><code>package my.package.configuration;

@Configuration
@PropertySource("classpath:application.properties")
public class AppConfig {

}
</code></pre>

<p>ServerConfig.java:</p>

<pre><code>public interface ServerConfig {
    String getUrl();
    String getUser();
    String getPassword();
}
</code></pre>

<p>ElasticSearchConfig.java:</p>

<pre><code>package my.package.configuration;

@Component(value = "elasticServerConfig")
public class ElasticServerConfig implements ServerConfig {

    private static final Logger LOGGER = LogManager.getLogger(ElasticServerConfig.class);

    private String url;
    private String user;
    private String password;

    @Autowired
    public ElasticServerConfig(final Environment env) {
        this.url = env.getProperty("elastic_server.url");
        this.user = env.getProperty("elastic_server.user");
        this.password = env.getProperty("elastic_server.password");
        LOGGER.debug("url=" + url + "; user=" + user + "; password=" + password); // this works!
    }

    @Override
    public final String getUrl() {
        return url;
    }

    @Override
    public final String getUser() {
        return user;
    }

    @Override
    public final String getPassword() {
        return password;
    }
}
</code></pre>

<p>When the web application boots, the ElasticServerConfig constructor prints out the correct url/user/pwd as read from application.properties. However an instance of ElasticServerConfig is not injected into a Search object:</p>

<pre><code>package my.package.util;

public class Search {

    @Autowired
    @Qualifier("elasticServerConfig") 
    private ServerConfig elasticServerConfig;

    public final List&lt;Foobar&gt; findByPatternAndLocation() {
      if (elasticServerConfig == null) {
         LOGGER.error("elasticServerConfig is null!");
      }
      // and i get a NullPointerException further on
      // snip
    }
}
</code></pre>