【串线篇】spring boot嵌入式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容器中剩下没有创建出的对象获取出来;
IOC容器启动创建嵌入式的Servlet容器
【串线篇】spring boot嵌入式Servlet容器启动原理;的更多相关文章
- 【串线篇】spring boot嵌入式Servlet容器自动配置原理
EmbeddedServletContainerAutoConfiguration:嵌入式的Servlet容器自动配置? @AutoConfigureOrder(Ordered.HIGHEST_PREC ...
- 4_8.springboot2.x嵌入式servlet容器启动原理解析
问题描述: 什么时候创建嵌入式的Servlet容器工厂? 什么时候获取嵌入式的Servlet容器并启动Tomcat? *获取嵌入式的Servlet容器工厂: 1).SpringBoot应用启动运行ru ...
- Spring Boot 嵌入式Web容器
目录 前言 1.起源 2.容器启动流程解析 2.1.获取应用类型 2.2.容器启动流程 3.加载 Web 容器工厂 4.总结 前言 最近在学习Spring Boot相关的课程,过程中以 ...
- spring boot配置Servlet容器
Spring boot 默认使用Tomcat作为嵌入式Servlet容器,只需要引入spring-boot-start-web依赖,默认采用的Tomcat作为容器 01 定制和修改Servlet容器 ...
- spring boot 监听容器启动
/** * 在容器启动的时候 加载没问完成的消息重发 * @author zhangyukun * */ @Component @Slf4j public class LoadMessageListe ...
- 【Spring Boot】Spring Boot之五种容器启动后进行相关应用初始化操作方法
一.方式一,使用ApplicationListener<E extends ApplicationEvent>监听ContextRefreshedEvent事件 /** * @author ...
- 嵌入式Servlet容器自动配置和启动原理
EmbeddedServletContainerAutoConfiguration:嵌入式的Servlet容器自动配置? @AutoConfigureOrder(Ordered.HIGHEST_PRE ...
- springboot(八) 嵌入式Servlet容器自动配置原理和容器启动原理
1.嵌入式Servlet容器自动配置原理 1.1 在spring-boot-autoconfigure-1.5.9.RELEASE.jar => springboot自动配置依赖 jar包下,E ...
- 18、配置嵌入式servlet容器(2)
使用其他Servlet容器 -Jetty(长连接) -Undertow(不支持jsp) 替换为其他嵌入式Servlet容器 默认支持: Tomcat(默认使用) Jetty: <depend ...
随机推荐
- IoC有什么好处
IoC(Inversion of Control):控制反转. DI(Dependency Injection):依赖注入. 控制反转是目的,依赖注入是实现控制反转的手段. 控制反转是一种面向对象的思 ...
- Dubbo负载均衡:最少活跃数(LeastActive)
官方文档定义 最少活跃调用数,相同活跃数的随机,活跃数指调用前后计数差. 使慢的提供者收到更少请求,因为越慢的提供者的调用前后计数差会越大. 关于活跃数 最少活跃数负载均衡,最关键的点在于活跃数.活跃 ...
- leetcode-mid-others-621. Task Scheduler
mycode 53.01% 这个题在纸上画一画就知道啦,只要出现次数最多的字母能够满足要求,其他更少的字母穿插在其中,间隔就更满足<n啦,当然,最后不要忘记加上尾巴哦,尾巴和出现次数最多的字 ...
- 在WCF程序中动态修改app.config配置文件
今天在个WCF程序中加入了修改配置文件的功能.我是直接通过IO操作修改的app.config文件内容,修改后发现发现其并不生效,用Google搜了一下,在园子里的文章动态修改App.Config 和w ...
- iOS证书详解
一.成员介绍1. Certification(证书)证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种:1) Developer Certification(开发证书)安装在电脑上 ...
- Linux监控命令之==>sar
一.使用说明 sar 是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况.系统调用的使用情况.磁盘I/O.CPU效率.内存使用状况.进程活动及 ...
- PARAMETERS对象
1. PARAMETERS的基本语法及定义 PARAMETERS可以参照数据字典字段或自定义数据类型创建文本输入域及单选框/复选框等, PARAMETERS只能创建一个单一的输入域且最多只能输入行,其 ...
- HTML5 表单的补充+注意事项
input标签中 type="image" 与 type="submit"属性 的区别 (下文简写image和submit) 1.这两者都可以响应请 ...
- Java ——接口
本节重点思维导图 定义: public interface Traffic { public static final int sits = 4; public abstract void run() ...
- lua正则表达式替换字符串
local _t = {} _t.name = "Li" local str = string.gsub("hahah---[name]----[age]--xrz-&q ...