需要ServletContext来配置默认的servlet处理

时间:2015-06-17 09:16:08

标签: spring spring-mvc spring-boot

我试图找出问题好几天但没有运气。我遇到了这个问题,但由于我没有在这里做任何测试,因此无法弄清楚是什么问题。 java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

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]

我正在使用春季靴子

@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<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
        initCachingHttpHeadersFilter(servletContext, disps);
            initStaticResourcesProductionFilter(servletContext, disps);
            initGzipFilter(servletContext, disps);
    }

现在问题出现在以下TypeToJsonMetadataConverter类的@Configuration bean定义中。

@Configuration
public class EntityRestMvcConfiguration extends RepositoryRestMvcConfiguration {
  @Bean
   public TypeToJsonMetadataConverter typeToJsonMetadataConverter() {
    return new TypeToJsonMetadataConverter(typeConfiguration(),
            entityLinks());
  }
  @Bean
  public TypeConfiguration typeConfiguration() {
    return new TypeConfiguration();
  }
}

0 个答案:

没有答案