SpringBoot 中filter在web容器中执行的顺序
1、调用 ServletWebServerApplicationContext.onStartup
2、获取所有的 ServletContextInitializer
3、initializers => 未排序的 Filter
4、sortedList => 排完序的Filter
5、实际循环的是排序后的Filter (sortedList)
误区:logMappings 打印的是initializers(非实际序列运行的Filter)
及开启web日志,出现【Mapping filters】开头的日志
logging:
level:
web: debug
2022-05-09 01:54:15.149 DEBUG [main] servlet.ServletContextInitializerBeans - Mapping filters: filterRegistrationBean urls=[/*] order=-2147483647, corsFilter urls=[/*] order=0, characterEncodingFilter urls=[/*] order=-2147483648, formContentFilter urls=[/*] order=-9900, requestContextFilter urls=[/*] order=-105, shiroFilter urls=[/*] order=2147483647 2022-05-09 01:54:15.149 DEBUG [main] servlet.ServletContextInitializerBeans - Mapping servlets: dispatcherServlet urls=[/]