I want to test my controller by using @WebMvcTest
. I @MockBean
the dependencies of the controller but when running the test, it fails to start. The
You must move all area-specific configuration, like @ComponentScan
and @EnableMongoRepositories
, to a separate @Configuration
file. It's important not to litter the application’s main class with configuration settings that are specific to a particular area of its functionality.
More information: https://docs.spring.io/spring-boot/docs/2.0.3.RELEASE/reference/htmlsingle/#boot-features-testing-spring-boot-applications-testing-user-configuration