MockBean annotation au Printemps de Démarrage test fait NoUniqueBeanDefinitionException

J'ai de la difficulté à l'aide de @MockBean annotation. Les docs disent MockBean peut remplacer un haricot dans le contexte, mais je suis un NoUniqueBeanDefinitionException au sein de mon unité de test. Je ne vois pas comment utiliser l'annotation. Si je peux me moquer des pensions, alors évidemment il n'y aura plus qu'un seul haricot définition.

Je suis en suivant les exemples trouvés ici: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4

J'ai un mongo référentiel:

public interface MyMongoRepository extends MongoRepository<MyDTO, String>
{
   MyDTO findById(String id);
}

Et un Maillot de ressources:

@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();
    }
}

Et un test JUnit:

@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);

    }

}

Message d'erreur:

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

OriginalL'auteur JCN | 2016-09-10