I updated to Spring boot 2.1 from Spring 2.0 and my service test failed.
My test structure:
com
...
service
ServiceTest.java
web
ControllerTest.java
ServiceTest.java:
@ExtendWith(SpringExtension.class)
@DataJpaTest
public class ServiceTest {
@Autowired
private OtherService otherService;
...
}
ControllerTest.java:
@ExtendWith(SpringExtension.class)
@WebMvcTest(secure = false)
@Import(WebMvcConfig.class)
@SuppressWarnings("Duplicates")
public class GroupControllerTest {
@Configuration
static class Config {
@Bean
public Controller controller() {
return new Controller();
}
}
}
During ServiceTest I get error:
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'controller' defined in class path resource [com/.../web/ControllerTest$Config.class]
How can spring get Config for ServiceTest from inner package-private class of GroupControllerTest? It's weird! Why does it scan sibling directory for config?