博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot--嵌入式Servlet容器启动原理
阅读量:2442 次
发布时间:2019-05-10

本文共 2887 字,大约阅读时间需要 9 分钟。

嵌入式Servlet容器启动原理

什么时候创建嵌入式的Servlet容器工厂?什么时候获取嵌入式的Servlet容器并启动Tomcat;

获取嵌入式的Servlet容器工厂:

1)、SpringBoot应用启动运行run方法

2)、refreshContext(context);SpringBoot刷新IOC容器【创建IOC容器对象,并初始化容器,创建容器中的每一个组件】;如果是web应用创建AnnotationConfigEmbeddedWebApplicationContext,否则:AnnotationConfigApplicationContext

3)、refresh(context);刷新刚才创建好的ioc容器;

public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// Prepare this context for refreshing. prepareRefresh(); // Tell the subclass to refresh the internal bean factory. ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. prepareBeanFactory(beanFactory); try {
// Allows post-processing of the bean factory in context subclasses. postProcessBeanFactory(beanFactory); // Invoke factory processors registered as beans in the context. invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation. registerBeanPostProcessors(beanFactory); // Initialize message source for this context. initMessageSource(); // Initialize event multicaster for this context. initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses. onRefresh(); // Check for listener beans and register them. registerListeners(); // Instantiate all remaining (non-lazy-init) singletons. finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. finishRefresh(); } catch (BeansException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Exception encountered during context initialization - " + "cancelling refresh attempt: " + ex); } // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset 'active' flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } finally {
// Reset common introspection caches in Spring's core, since we // might not ever need metadata for singleton beans anymore... resetCommonCaches(); } }}

4)、 onRefresh(); web的ioc容器重写了onRefresh方法

5)、webioc容器会创建嵌入式的Servlet容器;createEmbeddedServletContainer();

6)、获取嵌入式的Servlet容器工厂:

EmbeddedServletContainerFactory containerFactory = getEmbeddedServletContainerFactory();

​ 从ioc容器中获取EmbeddedServletContainerFactory 组件;TomcatEmbeddedServletContainerFactory创建对象,后置处理器一看是这个对象,就获取所有的定制器来先定制Servlet容器的相关配置;

7)、使用容器工厂获取嵌入式的Servlet容器:this.embeddedServletContainer = containerFactory .getEmbeddedServletContainer(getSelfInitializer());

8)、嵌入式的Servlet容器创建对象并启动Servlet容器;

先启动嵌入式的Servlet容器,再将ioc容器中剩下没有创建出的对象获取出来;

转载地址:http://ewpqb.baihongyu.com/

你可能感兴趣的文章
MailboxValidator –批量电子邮件列表清理服务
查看>>
机器学习中常见的最优化算法_最常见的机器学习算法
查看>>
css图片和边框之间有间隔_CSS和CSS3之间的区别
查看>>
iphone浏览器劫持修复_修复iPhone卡在Apple徽标问题上的问题
查看>>
5个最佳Python机器学习IDE
查看>>
c++中将字符串转化为数字_在C和C ++中将十进制数转换为罗马数字
查看>>
unity 粒子系统反弹_零反弹-最佳电子邮件验证系统
查看>>
rail_deviceid_C和C ++中的Rail Fence密码程序[加密和解密]
查看>>
数字转日期 pl/sql_交换两个数字的PL / SQL程序
查看>>
stl set容器_C ++ STL设置容器– std :: set
查看>>
HTML和HTML5之间的区别
查看>>
android mvp示例_Android使用SwipeRefreshLayout示例向下拉或向下滑动以刷新
查看>>
在Android中获取当前日期的4种方法
查看>>
使用Firebase教程的Android实时聊天应用程序
查看>>
evernote 云笔记_屏幕快照之旅:Windows版Evernote 4使记笔记变得很愉快
查看>>
windows便笺_如何将便笺提醒附加到Windows和应用程序
查看>>
加密货币钱包提供商_每日新闻摘要:一位加密货币钱包开发者为了保护用户而黑客攻击
查看>>
如何从Facebook迁移到Google+
查看>>
chromebook刷机_每日新闻摘要:Google终止了将Windows引入Chromebook的项目
查看>>
vue alexa:_免费下载:在任何PC上使用Alexa免提
查看>>