@Autowired object is always null : <p>I've started playing with spring data elasticsearch and have been looking at the example <a href="https://github.com/eugenp/tutorials/tree/master/persistence-modules/spring-data-elasticsearch" rel="nofollow noreferrer">here</a>.</p>

<p>I am having trouble understanding how <code>@Autowired</code> works. Consider the following:</p>

<p><strong>IMessageProcessor.java:</strong></p>

<pre><code>package message.processor;

public interface IMessageProcessor {
    void processMessage();
}
</code></pre>

<p><strong>MyMessageProcessor.java</strong></p>

<pre><code>package message.processor;

@Component
public class MyMessageProcessor implements IMessageProcessor {

    @Autowired
    private ArticleServiceImpl articleService;

    private final Author johnSmith = new Author("John Smith");
    private final Author johnDoe = new Author("John Doe");

    @Override
    public void processMessage() {
        Article article = new Article("Spring Data Elasticsearch");
        article.setAuthors(asList(johnSmith, johnDoe));
        article.setTags("elasticsearch", "spring data");
        articleService.save(article);       
    }   
}
</code></pre>

<p><strong>MyMessageProcessorIT.java</strong></p>

<pre><code>package message.processor;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Config.class)
public class MyMessageProcessorIT {

    @Autowired
    private ElasticsearchTemplate elasticsearchTemplate;

    @Before
    public void before() {
        elasticsearchTemplate.deleteIndex(Article.class);
        elasticsearchTemplate.createIndex(Article.class);
    }

    @Test
    void testProcessMessage() {
        MyMessageProcessor msgProcessor = new MyMessageProcessor();
        msgProcessor.processMessage();
    }
}
</code></pre>

<p>Whenever I run the unit test, <code>articleService</code> in <code>MyMessageProcessor</code> is always <code>null</code>. Do I need extra configuration for the autowiring to work? All other code is the same as what is in the github repo linked above.</p>

<p>How do I ensure that wherever in my project I need to use <code>ArticleServiceImpl</code>, it is autowired correctly?</p>

<p>I have seem other posts with the same issue but none of the solutions seem to work for my example below.</p>
