In my Spring Boot project with two submodules main-module and service-module. The main-module has an Application class with @SpringBootApplication. The service-module has a ServiceConfig class marked with @Configuration and @ComponentScan that scans the basePackage. When running a unit test in the service-module annotated with @SpringApplicationConfiguration(classes = ServiceConfig), I get the following error: Failed to load ApplicationContext.
If I add the following class in the test package, the unit test passes:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class TestConfig {
}
Why is the TestConfig needed? Shouldn't the ServiceConfig suffice to set up the ApplicationContext?
Aucun commentaire:
Enregistrer un commentaire