SpringBoot中,嵌入环境中的Tomcat忽略ServletContainerInitializer

2017-07-19 16:31:44来源:oschina作者:yongk人点击

按照@philwebb说法,嵌入式环境下,SpringBoot有意忽略javax.servlet.ServletContainerInitializer,原因:



The search algorithm used by the containers was problematic. It also causes problems when you want to develop an executable WAR as you often want a javax.servlet.ServletContainerInitializer for the WAR that is not executed when you run java -jar.



解决方案:


1. 注册org.springframework.boot.context.embedded.ServletContextInitializer类型的Bean代替ServletContainerInitializer。


2. 直接向容器注册Servlet和Filter。


3. 向容器注册ServletRegistrationBean和FilterRegistrationBean。

参考:


[1]https://github.com/spring-projects/spring-boot/issues/321


[2]https://github.com/spring-projects/spring-boot/issues/522

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台