title: MockBean annotation in Spring Boot test causes NoUniqueBeanDefinitionException
body: <p>I am having trouble using the @MockBean annotation. The docs say MockBean can replace a bean within the context, but I am getting a NoUniqueBeanDefinitionException within my unit test. I can't see how to use the annotation. If I can mock the repo, then obviously there will be more than one bean definition.</p>
  
  <p>I am following the examples found here: <a href="https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4" rel="noreferrer">https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4</a></p>
  
  <p>I have a mongo repository:</p>
  
  <pre><code>public interface MyMongoRepository extends MongoRepository&lt;MyDTO, String&gt;
  {
     MyDTO findById(String id);
  }
  </code></pre>
  
  <p>And a Jersey resource:</p>
  
  <pre><code>@Component
  @Path("/createMatch")
  public class Create
  {
      @Context
      UriInfo uriInfo;
  
      @Autowired
      private MyMongoRepository repository;
  
      @POST
      @Produces(MediaType.APPLICATION_JSON)
      public Response createMatch(@Context HttpServletResponse response)
      {
          MyDTO match = new MyDTO();
          match = repository.save(match);
          URI matchUri = uriInfo.getBaseUriBuilder().path(String.format("/%s/details", match.getId())).build();
  
          return Response.created(matchUri)
                  .entity(new MyResponseEntity(Response.Status.CREATED, match, "Match created: " + matchUri))
                  .build();
      }
  }
  </code></pre>
  
  <p>And a JUnit test:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class TestMocks {
  
      @Autowired
      private TestRestTemplate restTemplate;
  
      @MockBean
      private MyMongoRepository mockRepo;
  
      @Before
      public void setup()
      {
          MockitoAnnotations.initMocks(this);
  
          given(this.mockRepo.findById("1234")).willReturn(
                  new MyDTO());
      }
  
      @Test
      public void test()
      {
          this.restTemplate.getForEntity("/1234/details", MyResponseEntity.class);
  
      }
  
  }
  </code></pre>
  
  <p>Error message:</p>
  
  <pre><code>Field repository in path.to.my.resources.Create required a single bean, but 2 were found:
      - myMongoRepository: defined in null
      - path.to.my.MyMongoRepository#0: defined by method 'createMock' in null
  </code></pre>