getWebServer会调用ServletContextInitializer#onStartup,即若想在Servlet容器启动时做一些事情,比如注册自己的Servlet,可以实现一个ServletContextInitializer,在Web容器启动时,Spring Boot会把所有实现ServletContextInitializer接口的类收集起来,统一调其onStartup。
WebServerFactoryCustomizerBeanPostProcessor
一个BeanPostProcessor,为定制化嵌入式Web容器,在postProcessBeforeInitialization过程中去寻找Spring容器中WebServerFactoryCustomizer类型的Bean,并依次调用WebServerFactoryCustomizer接口的customize方法做一些定制化。
public interface WebServerFactoryCustomizer {
void customize(T factory);
}
============================================================================
Spring的ApplicationContext,其抽象实现类AbstractApplicationContext#refresh
用来新建或刷新一个ApplicationContext,在refresh中会调用onRefresh,AbstractApplicationContext的子类可以重写onRefresh实现Context刷新逻辑。
因此重写 ServletWebServerApplicationContext#onRefresh 创建嵌入式Web容器: