title: JUnit test with Spring and mongodb: could not autowire repository
body: <p>I have problem writing a test with Spring and JUnit to test a MongoDB respository. The message is "could not autowire. No beans of ... type found"
  My repository is</p>
  
  <pre><code>public interface ProjectRepository extends MongoRepository&lt;Project, String&gt; {
  
  public Project findByName(String name);
  
  }
  </code></pre>
  
  <p>while my configuration file is</p>
  
  <pre><code>@Configuration
  @EnableMongoRepositories(basePackageClasses = RepositoryPackage.class)
  public class SpringMongoConfiguration extends AbstractMongoConfiguration{
  
  
  @Override
  protected String getDatabaseName() {
      return "test";
  }
  
  @Bean
  public MongoClient mongo() throws Exception {
  
      MongoClient client = new MongoClient("localhost");
      return client;
  }
  
  @Bean
  public MongoTemplate mongoTemplate() throws Exception {
      return new MongoTemplate(mongo(), getDatabaseName());
  }
  
  }
  </code></pre>
  
  <p>where RepositoryPackage is in the same package of the repository. 
  My test is</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = SpringMongoConfiguration.class)
  public class MongoDbProjectTests {
  
  @Autowired
  private ProjectRepository projectRepository;
  
  @Before
  public void init(){
  
      projectRepository.deleteAll();
      Project project = new Project("sdfjklgh", 1, "comunione Leonardo",
              Project.TYPE_PROJECT_PHOTO, Project.STATE_PROJECT_DRAFT);
  
      projectRepository.save(project);
  }
  
  @Test
  public void test1(){
      List&lt;Project&gt; list = projectRepository.findAll();
      assertEquals(1, list.size());
  }
  
  }
  </code></pre>
  
  <p>what am I doing wrong?</p>