title: A ServletContext is required to configure default servlet handling
body: <p>I am trying to figure out a issue for some days but no luck. I came across this issue but not able figure out what is the problem since i am not doing any test here. <a href="https://stackoverflow.com/questions/21516683/java-lang-illegalargumentexception-a-servletcontext-is-required-to-configure-de">java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling</a></p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
  </code></pre>
  
  <p>I am using spring boot</p>
  
  <pre><code>@ComponentScan
  @EnableAutoConfiguration
  public class Application {
     .....
  }
  
  public class ApplicationWebXml extends SpringBootServletInitializer {
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(Application.class);
  }
  
  @Configuration
  @AutoConfigureAfter
  public class WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer {
      @Override
      public void onStartup(ServletContext servletContext) throws ServletException {
          EnumSet&lt;DispatcherType&gt; disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
          initCachingHttpHeadersFilter(servletContext, disps);
              initStaticResourcesProductionFilter(servletContext, disps);
              initGzipFilter(servletContext, disps);
      }
  </code></pre>
  
  <p>Now the problem is coming in <code>TypeToJsonMetadataConverter</code> bean definition in the following <code>@Configuration</code> classes. </p>
  
  <pre><code>@Configuration
  public class EntityRestMvcConfiguration extends RepositoryRestMvcConfiguration {
    @Bean
     public TypeToJsonMetadataConverter typeToJsonMetadataConverter() {
      return new TypeToJsonMetadataConverter(typeConfiguration(),
              entityLinks());
    }
    @Bean
    public TypeConfiguration typeConfiguration() {
      return new TypeConfiguration();
    }
  }
  </code></pre>