【发布时间】:2020-01-12 20:42:00
【问题描述】:
我正在尝试为 SpringBoot 2 创建一个自定义的嵌入式 servlet 容器。我已经创建了 ServletWebServerFactory 和 WebServer 接口的实现。在我的应用程序中,我从spring-boot-starter-web 中明确排除了嵌入式Tomcat,然后手动将我的自定义工厂类提供给SpringApplication 构造函数。当我的WebServer 实现的start() 方法被调用时,我将我的ServletContext 提供给传递给工厂的getWebServer 方法的所有ServletContextInitializers。
当我调用SpringApplication 的run() 方法时,我可以看到Spring 正在加载我的工厂并正确抓取我的WebServer 对象。但是,启动失败并出现以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
我错过了什么?我应该将ServletContext 传递到另一个地方吗?
【问题讨论】:
标签: java spring spring-boot spring-mvc servlets