title: Register spring data repository interface as bean in a java configuration
body: <p>I have a spring data repository interface and I want to register it as a <code>@Bean</code> in my java configuration. The reason I want to do this is because the <code>@Bean</code> annotation also allows me to have alias (if I provide more than one name for the bean). I cannot do this:
  <code>
  @Bean(name = {"defaultMyRepo", "myRepo"})
  public MyRepository defaultMyRepository() {
      return new MyRepository();
  }
  </code></p>
  
  <p>because <code>MyRepository</code> is an interface and I cannot instantiate it.</p>
  
  <p>The problem occurs when I try to create a bean in my configuration like this:</p>
  
  <pre><code>@Bean(name = { "defaultSearchProductExportWriter", "searchProductExportWriter" })
  public RepositoryItemWriter&lt;Serializable&gt; defaultSearchProductExportWriter() {
      final RepositoryItemWriter&lt;Serializable&gt; itemWriter = new RepositoryItemWriter&lt;&gt;();
      itemWriter.setRepository(applicationContext.getBean(ProductSearchRepository.class));
      itemWriter.setMethodName("save");
  
      return itemWriter;
  }
  </code></pre>
  
  <p>Now this will blow with <code>multiple beans found, expected 1 but found 2</code>. I also tried passing the required bean as a parameter to the method:</p>
  
  <pre><code>@Bean(name = { "defaultSearchProductExportWriter", "searchProductExportWriter" })
  public RepositoryItemWriter&lt;Serializable&gt; defaultSearchProductExportWriter(final ProductSearchRepository repository) {
      final RepositoryItemWriter&lt;Serializable&gt; itemWriter = new RepositoryItemWriter&lt;&gt;();
      itemWriter.setRepository(repository);
      itemWriter.setMethodName("save");
  
      return itemWriter;
  }
  </code></pre>
  
  <p>but I got exactly the same exception. It only works if I define the repository interface with a name and alias, and then the overriding bean with different-name and the same alias. This way I can use the <code>@Qualifier("myAlias")</code> and it will find the correct overriding repository interface.</p>
  
  <p>This could also be a potential feature request for the spring-data repositories to change the <code>value</code> attribute of the <code>@Repository</code> annotation to be <code>String[]</code> so that we can also register aliases.</p>