title: JerseyTest and Spring and creating a ServletContext
body: <p>I'm working on migrating from Jersey 1.16 to Jersey 2.7. I have the application running and working, but I'm having trouble with the tests.</p>
  
  <p>Some things to note:<br>
  The application uses Spring and is configured by a class, ApplicationConfiguration.class. 
  The application does not have a web.xml - the Jersey servlet and filters are configured programmatically.
  I am using the jersey-spring3 library.
  Related to using the jersey-spring3 library, I have to add a workaround to my onStartup method</p>
  
  <pre><code>// The following line is required to avoid having jersey-spring3 registering it's own Spring root     context.
  // https://java.net/jira/browse/JERSEY-2038
  servletContext.setInitParameter("contextConfigLocation", "");
  </code></pre>
  
  <p>Here's the issue:<br>
  When the test is starting up, SpringComponentProvider, tries to initialize Spring with a dangerous assumption that I can't figure out how to correct - xml based configuration. Looking at the code, the trouble is this block</p>
  
  <pre><code>    ServletContext sc = locator.getService(ServletContext.class);
  
      if(sc != null) {
          // servlet container
          ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
      } else {
          // non-servlet container
          ctx = createSpringContext();
      }
  </code></pre>
  
  <p>Running a JUnit test, ServletContext is null, and createSpringContext is called.</p>
  
  <p>Here's the question:<br>
  Is there a way to run a test and specify a ServletContext/ServletContainer?</p>