title: Overwrite Java based Spring Context Configuration for Tests
body: <p>Is there a possibility to replace a single bean or value from a Spring configuration for one or more integration tests?</p>
  
  <p>In my case, I have the configuration</p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration
  @ComponentScan(basePackages = {"foo.bar"})
  public class MyIntegrationTestConfig {
      // everything done by component scan
  }
  </code></pre>
  
  <p>Which is used for my integration test</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = MyIntegrationTestConfig.class, loader = SpringApplicationContextLoader.class)
  public class MyIntegrationTest {
      // do the tests
  }
  </code></pre>
  
  <p>Now I want to have a second set of integration tests where I replace one bean by a different one. </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = MyIntegrationTestConfig.class, loader = SpringApplicationContextLoader.class)
  public class MySpecialIntegrationTest {
      // influence the context configuration such that a bean different from the primary is loaded
  
      // do the tests using the 'overwritten' bean
  }
  </code></pre>
  
  <p>What is the most simple way to achieve this?</p>