private void postProcessBeforeInitialization(WebServerFactory webServerFactory) { // 找到WebServerFactoryCustomizer的Bean LambdaSafe.callbacks(WebServerFactoryCustomizer.class, getCustomizers(), webServerFactory) // 标记日志用的类 .withLogger(WebServerFactoryCustomizerBeanPostProcessor.class) // 调用customize方法,传入webServerFactory .invoke((customizer) -> customizer.customize(webServerFactory));}
- postProcessBeforeInitialization中会调用WebServerFactoryCustomizer类customize方法,在系统中的唯一实现:ServletWebServerFactoryCustomizer的customize方法 。
- customize把配置中的内容设置到ConfigurableServletWebServerFactory对象中 。他的实现TomcatServletWebServerFactory在启动的时候就会有值!
@Overridepublic void customize(ConfigurableServletWebServerFactory factory) { PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); map.from(this.serverProperties::getPort).to(factory::setPort); map.from(this.serverProperties::getAddress).to(factory::setAddress); map.from(this.serverProperties.getServlet()::getContextPath).to(factory::setContextPath); map.from(this.serverProperties.getServlet()::getApplicationDisplayName).to(factory::setDisplayName); map.from(this.serverProperties.getServlet()::isRegisterDefaultServlet).to(factory::setRegisterDefaultServlet); map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession); map.from(this.serverProperties::getSsl).to(factory::setSsl); map.from(this.serverProperties.getServlet()::getJsp).to(factory::setJsp); map.from(this.serverProperties::getCompression).to(factory::setCompression); map.from(this.serverProperties::getHttp2).to(factory::setHttp2); map.from(this.serverProperties::getServerHeader).to(factory::setServerHeader); map.from(this.serverProperties.getServlet()::getContextParameters).to(factory::setInitParameters); map.from(this.serverProperties.getShutdown()).to(factory::setShutdown); for (WebListenerRegistrar registrar : this.webListenerRegistrars) { registrar.register(factory); } if (!CollectionUtils.isEmpty(this.cookieSameSiteSuppliers)) { factory.setCookieSameSiteSuppliers(this.cookieSameSiteSuppliers); }}ServletWebServerFactoryCustomizer这个Bean是哪里的?
- 在我们自动配置类ServletWebServerFactoryAutoConfiguration中定义 。
@Beanpublic ServletWebServerFactoryCustomizer servletWebServerFactoryCustomizer(ServerProperties serverProperties, ObjectProvider<WebListenerRegistrar> webListenerRegistrars, ObjectProvider<CookieSameSiteSupplier> cookieSameSiteSuppliers) { return new ServletWebServerFactoryCustomizer(serverProperties,webListenerRegistrars.orderedStream().collect(Collectors.toList()),cookieSameSiteSuppliers.orderedStream().collect(Collectors.toList()));}
【【Spring boot】整合tomcat底层原理】
经验总结扩展阅读
-
dnf tgp怎么手动截图(新版tgp怎么看dnf截图)
-
-
-
-
-
-
-
-
-
仙剑奇侠传80后古装俊,90后帅,00后美,谁是你心中最爱的古装美男
-
化妆|亚洲四大邪术的化妆有多厉害老外看第一眼直言简直怀疑人生
-
-
-
-
-
2022年11月21日安装门框吉日一览表 2022年农历十月廿八宜安装门框吗
-
-
电脑win7取消分屏模式的方法 怎么取消win7电脑分屏
-
自学英文都有哪些免费app呢,自学英语app哪个好 推荐一下免费
-
严重人到中年,经常吃这3种食物,头发变乌黑了,连皮肤都跟着变好了