lundi 16 mars 2020

Testing a controller with duplicate name using WebMvcTest

I have 2 controllers wih the same name, in two different packages :

package1.MyController
package2.MyController

I want to test the controller in package1, using WebMvcTest. So I specify the name and package of the controller in the @WebMvcTest annotation, like this :

@WebMvcTest(value = package1.MyController.class) (I assume Spring will know which controller i want to test)

But I get the following error : Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'MyController' for bean class [package1.MyController] conflicts with existing, non-compatible bean definition of same name and class [package2.MyController]

Can someone explain that to me? And is there a way to tell Spring which controller class I want to test (except giving them different names, of course)? Adding a different bean name on each controller seams useless because the parameter on WebMvcTest only accepts class names.

Aucun commentaire:

Enregistrer un commentaire