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