title: How can I initialize a Spring applicationContext just once for all tests
body: <p>I have a set of tests based which need a spring context.</p>
  
  <p>For fast test execution I want to make sure that the Spring context is initialized just once, then all the tests should be run against this context, then it should shut down.</p>
  
  <p>I already tried the following approaches:</p>
  
  <ol>
  <li>Use <code>@RunWith(SpringJUnit4ClassRunner.class)</code> and <code>@ContextConfiguration(MyAnnotatedConfig.class)</code> to initialize the spring context</li>
  <li>Use a <code>@RunWith(SpringJUnit4ClassRunner.class)</code> and <code>@TestExecutionListeners({MyTestExecutionListener.class})</code> with a handwritten test execution listener that initializes the spring context and injects it into the concrete test classes</li>
  <li>Use a <code>@BeforeClass</code> listener in a base class and a static field to store the spring context, and a <code>@AfterClass</code> for shutdown</li>
  </ol>
  
  <p>With all three approaches, the spring context seems to be initialized more than once, which takes a lot of time. It seems that JUnit unloads classes while running tests, so that the content of static fields is sometimes lost.</p>
  
  <p>Is there a way to make sure the spring context is initialized only once?</p>