I'm trying to run a @SpringBootTest
in a "clean" context without having MyApplicationContextInitializer
executed.
The MyApplicationContextInitializer
is included inside the spring.factories
file in a compile-scope
dependency like this:
org.springframework.context.ApplicationContextInitializer=\
com.eremic.myapp.MyApplicationContextInitializer
Test class:
@SpringBootTest(webEnvironment = RANDOM_PORT)
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = TestContext.class)
public class UsersControllerTest {}
Test config:
@SpringBootConfiguration
public class TestContext {}
Is there a way to exclude MyApplicationContextInitializer
from @SpringBootTest
?
I've already tired with excludeFilters @ComponentScan.Filters
, but it has no effect on ApplicationContextInitializer.
Also, I've tried to annotate TestContext
with @SpringBootApplication
and to limit component scanning with scanBasePackages
and/or to use exclude = MyApplicationContextInitializer.class
but it has no effect too.
So far the only way to prevent MyApplicationContextInitializer
from executing inside @SpringBootTest
is to remove the maven dependency in which the MyApplicationContextInitializer
is declared.