简体   繁体   中英

Spring-Boot Application Context with ArangoDB-Repository cannot be created if using @MockBean

We are developing a Spring-Boot application which uses ArangoDB with the Spring-Data integration of the ArangoDB team itself ( https://github.com/arangodb/spring-data ).

We ran into some weird problem when we tried to develop integration tests: when we used @MockBean annotations in test classes for unrelated Spring components, the application context could not be created:

org.springframework.beans.factory.UnsatisfiedDependencyException:
   Error  creating bean with name 'repository': Unsatisfied dependency 
   expressed through constructor parameter 1: Ambiguous argument values for 
   parameter of type [com.arangodb.springframework.core.ArangoOperations] - 
   did you specify the correct bean references as arguments?

It seems that the mere presence of the @MockBean Annotation produces this error.

Also, Eclipse with installed Spring Tools shows the following error on the Main class:

No constructor with 1 argument defined in class
'com.arangodb.springframework.repository.ArangoRepositoryFactoryBean'

This error message seems to be true as there only is a two-argument constructor for this factory. The tests without @MockBean do run successfully, regardless.

Example

We stripped out project down to a minimal example which you can find on GitHub: https://github.com/mark--/arango-mockbean-error

The relevant code is in the single test class DAOTest. If the @MockBean annotation is present the error from above occurs, if it is removed the application context is created.

Beware : We removed the test setup code in the example project, in particular the setup of an ArangoDB instance with docker: as a consequence the test fails also without the @MockBean annotation but only due to the missing ArangoDB.

Update :

The workaround from MockBean annotation in Spring Boot test causes NoUniqueBeanDefinitionException (give the @MockBean a name) works for us, too, so this seems to be some Spring bug.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM