title: How to configure MessageDispatcherServlet programmatically
body: <p>I am trying to learn spring-ws and started with this tutorial:
  <a href="http://spring.io/guides/gs/producing-web-service/#initial" rel="nofollow noreferrer">http://spring.io/guides/gs/producing-web-service/#initial</a>.</p>
  
  <p>What I would like to do now is to start the service on non-embedded servlet container by configuring the application programmatically.</p>
  
  <p>I am stuck on how to setup Message Dispatcher Servlet without web.xml. What i tried to is to 
  implement WebApplicationInitializer interface's method onStartup(ServletContext servletContext).</p>
  
  <pre><code>public class ServerInitializer  implements WebApplicationInitializer{
  
      public void onStartup(ServletContext servletContext) throws ServletException {
  
          AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
          context.setConfigLocation(WebServiceConfig.class.getName());
          servletContext.addListener(new ContextLoaderListener(context));
  
          MessageDispatcherServlet servlet = new MessageDispatcherServlet();
          servlet.setApplicationContext(context);
          servlet.setTransformWsdlLocations(true);
  
  
          // Create dispatcher for named context
          ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("DispatcherServlet", servlet);
  
          // Load on startup
          dispatcherServlet.setLoadOnStartup(1);
  
          // Add URL mapping for dispatcher
          dispatcherServlet.addMapping("/*");
  
  
      }
  
  }
  </code></pre>
  
  <p>However, when i deploy this to tomcat, requests i send with SOAP UI( which are working on tutorial sample) are never getting mapped</p>