Ignored by Beans in SpringBootTest config
I have the following structure:
Main configuration class;
@TestConfiguration
@Import({MainApplication.class, ConfigA.class, ConfigB.class})
public class MainTestConfiguration {
}
And two separate classes of configuration;
@TestConfiguration
public class ConfigA {
@Bean
public EtcDao etcDao() {
// return custom etcDao
}
}
@TestConfiguration
public class ConfigB {
@Bean
public SomeBean someBean() {
// return custom someBean
}
}
And the test is as follows:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainTestConfiguration.class)
public class MotherTest {
@Test
public void test() {
// test
}
}
In this framework, my test beans definitions are EtcDao
both SomeBean
ignored and the main context definitions of those beans (from MainApplication.class
) are used. But if I include these separate configurations in @SpringBootTest
like @SpringBootTest(classes = {ConfigA.class, ConfigB.class})
, then it works correctly. Doesn't @Include
allow initialization of beans in these separate configuration classes? Or the culprit is my inclusion MainApplication.class
along with them, but I needed a different configuration, so I had to implement this way.
source to share
No one has answered this question yet
Check out similar questions: