我想使用嵌入式Tomcat在Spring Boot 2中以编程方式注册servlet。
我发现here可以使用WebApplicationInitializer
来实现。后来我意识到这种方法确实not work with embedded Tomcat。
答案 0 :(得分:1)
使用ServletRegistrationBean会怎样?
@Bean
public ServletRegistrationBean servletRegistrationBean(){
return new ServletRegistrationBean(new FooServlet(),"/someOtherUrl/*");
}