Spring Boot 2中的程序化servlet注册

时间:2019-04-23 07:11:20

标签: spring-boot

我想使用嵌入式Tomcat在Spring Boot 2中以编程方式注册servlet。

我发现here可以使用WebApplicationInitializer来实现。后来我意识到这种方法确实not work with embedded Tomcat

1 个答案:

答案 0 :(得分:1)

使用ServletRegistrationBean会怎样?

@Bean
public ServletRegistrationBean servletRegistrationBean(){
    return new ServletRegistrationBean(new FooServlet(),"/someOtherUrl/*");
}