title: Spring MVC and Spring WS dispatcher servlet configuration in one web application
body: <p>I trying to implement both spring rest and soap in same application .I configured two separate configurations for REST and SOAP.But im unable to start the server because im getting below exception 
  "Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext".
  Help me to define both dispatcher servlet in java config.</p>
  
  <p>My classes :</p>
  
  <p>REST API COnfiguration:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = { "com.test.test1.*" })
  public class RestConfiguration extends WebMvcConfigurerAdapter {
  
      @Override
      public void configureMessageConverters(
              List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) {
          converters.add(extendedJsonConvertor());
          super.configureMessageConverters(converters);
      }
      @Bean
      public MappingJackson2HttpMessageConverter extendedJsonConvertor() {
          MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
  
          mappingJackson2HttpMessageConverter
                  .setObjectMapper(getNullAndEmptyFilteredObjectMapper());
          return mappingJackson2HttpMessageConverter;
      }
  
      /**
       * Gets the null and empty filtered object mapper.
       *
       */
      @Bean
      public ObjectMapper getNullAndEmptyFilteredObjectMapper() {
          ObjectMapper objectMapper = new ObjectMapper();
         // objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);        
          DateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy hh:mm:ss");
          objectMapper.setDateFormat(dateFormat);
          return objectMapper;
      }
  
  
  
  }
  </code></pre>
  
  <p>REST MVC COnfiguration:</p>
  
  <pre><code>public class RESTMvcConfiguration extends
          AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class&lt;?&gt;[0];
      }
  
      @Override
      protected String getServletName() {
          return "REST";
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class&lt;?&gt;[] { RestConfiguration.class };
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { "/" };
      }
  }
  </code></pre>
  
  <p>SOAP COnfiguration:</p>
  
  <pre><code>@EnableWs
  @Configuration
  @ComponentScan(basePackages = { "com.test.test1.*" })
  public class SoapServiceConfiguration extends WsConfigurerAdapter {
      @Bean
      public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
          MessageDispatcherServlet servlet = new MessageDispatcherServlet();
          servlet.setApplicationContext(applicationContext);
          servlet.setTransformWsdlLocations(true);
          return new ServletRegistrationBean(servlet, "/ws/*");
      }
  
      @Bean(name = "country")
      public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
          DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
          wsdl11Definition.setPortTypeName("CountryPort");
          wsdl11Definition.setLocationUri("/ws");
          wsdl11Definition.setTargetNamespace("http://test.*.*.com");
          wsdl11Definition.setSchema(countriesSchema);
          return wsdl11Definition;
      }
  
      @Bean
      public XsdSchema countriesSchema() {
          return new SimpleXsdSchema(new ClassPathResource("country.xsd"));
      }
  }
  </code></pre>
  
  <p>SOAP MVC COnfiguration:</p>
  
  <pre><code>public class SoapMvcConfiguration extends
          AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class&lt;?&gt;[0];
      }
  
      @Override
      protected String getServletName() {
          return "SOAP";
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class&lt;?&gt;[] { SoapServiceConfiguration.class };
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] { "/" };
      }
  
      }
  </code></pre>
  
  <p>Exception</p>
  
  <pre><code>01:14:51.978 [localhost-startStop-1] DEBUG c.a.c.c.RESTMvcConfiguration - No ContextLoaderListener registered, as createRootApplicationContext() did not return an application context
  01:14:52.104 [localhost-startStop-1] DEBUG c.a.c.s.c.SoapMvcConfiguration - No ContextLoaderListener registered, as createRootApplicationContext() did not return an application context
  May 05, 2016 1:14:52 AM org.apache.catalina.core.ContainerBase startInternal
  SEVERE: A child container failed during start
  java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TEST]]
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:188)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1122)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/TEST]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      ... 6 more
  Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
      at org.apache.tomcat.websocket.server.WsServerContainer.&lt;init&gt;(WsServerContainer.java:149)
      at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)
      at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5580)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 6 more
  </code></pre>