title: How to make instance of CrudRepository interface during testing in Spring?
body: <p>I have a Spring application and in it I <strong>do not</strong> use xml configuration, only Java Config. Everything is OK, but when I try to <em>test</em> it I faced problems with enabling autowiring of components in the tests. So let's begin. I have an <strong><em>interface</em></strong>:</p>
  
  <pre><code>@Repository
  public interface ArticleRepository extends CrudRepository&lt;Page, Long&gt; {
      Article findByLink(String name);
      void delete(Page page);
  }
  </code></pre>
  
  <p>And a component/service:</p>
  
  <pre><code>@Service
  public class ArticleServiceImpl implements ArticleService {
      @Autowired
      private ArticleRepository articleRepository;
  ...
  }
  </code></pre>
  
  <p>I don't want to use xml configurations so for my tests I try to test ArticleServiceImpl  using only Java Configuration. So for the test purpose I made:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = {"com.example.core", "com.example.repository"})
  public class PagesTestConfiguration {
  
  
  @Bean
  public ArticleRepository articleRepository() {
         // (1) What to return ?
  }
  
  @Bean
  public ArticleServiceImpl articleServiceImpl() {
      ArticleServiceImpl articleServiceImpl = new ArticleServiceImpl();
      articleServiceImpl.setArticleRepository(articleRepository());
      return articleServiceImpl;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>In <strong>articleServiceImpl</strong>() I need to put instance of <strong>articleRepository</strong>() but it is an interface. How to create new object with new keyword? Is it possible without creating xml configuration class and enable Autowiring? Can autowired be enabled when using only JavaConfigurations during testing?</p>