Spring boot SpringBoot2中的编程servlet注册

Spring boot SpringBoot2中的编程servlet注册,spring-boot,Spring Boot,我想使用嵌入式Tomcat在SpringBoot2中以编程方式注册servlet 我发现使用WebApplicationInitializer可以实现这一点。后来,我意识到这种方法确实有效。使用它怎么样 您正在使用Spring Boot,您是否考虑过阅读?我将重新讨论这个问题,谢谢。我猜这个问题有点重复:)如果您的意思是回答,那么是的。但这是对你问题的回答,还是你在问一些不同的问题?是的。谢谢你的反馈。 @Bean public ServletRegistrationBean servletRe

我想使用嵌入式Tomcat在SpringBoot2中以编程方式注册servlet

我发现使用
WebApplicationInitializer
可以实现这一点。后来,我意识到这种方法确实有效。

使用它怎么样


您正在使用Spring Boot,您是否考虑过阅读?我将重新讨论这个问题,谢谢。我猜这个问题有点重复:)如果您的意思是回答,那么是的。但这是对你问题的回答,还是你在问一些不同的问题?是的。谢谢你的反馈。
@Bean
public ServletRegistrationBean servletRegistrationBean(){
    return new ServletRegistrationBean(new FooServlet(),"/someOtherUrl/*");
}