title: Migrating from web.xml to Java based configuration - unable to start Tomcat 8
body: <p>I am trying to migrate my app's web.xml to Java based configuration.
  We are using spring 4.1, Java 7, Servlet 3.1, Tomcat 8 and Eclipse Luna.
  The web service framework is Jersey 2.14.</p>
  
  <p>I used mainly the following guide: <a href="http://www.robinhowlett.com/blog/2013/02/13/spring-app-migration-from-xml-to-java-based-config/" rel="nofollow">http://www.robinhowlett.com/blog/2013/02/13/spring-app-migration-from-xml-to-java-based-config/</a></p>
  
  <p>I have created WebApplicationInitializer that follows the web.xml configuration, deleted the web.xml, configured Maven not to look for web.xml and did mvn clean install successfuly.</p>
  
  <p>When i try to start tomcat i get the following error:</p>
  
  <pre><code>'Publishing to Tomcat v8.o Server at localhost...' has encountered a problem. Resource '/sb-server/target/m2e-wtp/web-resources/WEB-INF/web.xml' does not exist.
  </code></pre>
  
  <p>I have tried to clean tomcat directory but it didn't help and it looks like i have missed something since AFAIK Tomcat 8 should be Java-Based-Configuration-Friendly.</p>
  
  <p>Did i miss a step in the migration?</p>
  
  <p>former web.xml (that worked as expected):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0"&gt; 
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextClass&lt;/param-name&gt;
          &lt;param-value&gt;
      org.springframework.web.context.support.AnnotationConfigWebApplicationContext
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              com.sb.configuration.ServerConfiguration
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
              org.glassfish.jersey.servlet.ServletContainer
          &lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt;
              &lt;param-value&gt;com.sb.configuration.RestJaxRsApplication&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.tracing.type&lt;/param-name&gt;
              &lt;param-value&gt;ALL&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/api/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;!-- Spring Security --&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy
          &lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The WebApplicationInitializerImplemenatation:</p>
  
  <pre><code>@Order(Ordered.HIGHEST_PRECEDENCE)
  public class WebAppInitializer implements WebApplicationInitializer {
  
      @Override
      public void onStartup(final ServletContext container) throws ServletException {
  
          // Set up application context
          final AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
          appContext.register(ServerConfiguration.class);
          container.addListener(new ContextLoaderListener(appContext));
  
          // Register listeners
          container.addListener(ContextLoaderListener.class);
  
          // Jersey Servlet configuration
          final ServletRegistration.Dynamic dispatcher =
                  container.addServlet("Jersey REST Service", ServletContainer.class);
          dispatcher.setInitParameter("javax.ws.rs.Application", "com.sb.configuration.RestJaxRsApplication");
  
          dispatcher.setInitParameter("jersey.config.server.tracing.type", "ALL");
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/api/*");
  
          // Filters
          final Dynamic filterRegistration = container.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
          filterRegistration.addMappingForUrlPatterns(null, false, "/*");
  
      }
  }
  </code></pre>