File tree Expand file tree Collapse file tree 2 files changed +43
-3
lines changed
Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change 101101
102102[ Spring Boot总结] ( 框架/SpringBoot实战.md )
103103
104- [ SpringBoot自动配置原理 ] ( 框架/SpringBoot自动配置原理 .md )
104+ [ SpringBoot面试题总结 ] ( 框架/SpringBoot面试题总结 .md )
105105
106106## Spring MVC
107107
Original file line number Diff line number Diff line change 77
88<!-- END doctoc generated TOC please keep comment here to allow auto update -->
99
10- # 自动配置原理
10+ ## 自动配置原理
1111
1212SpringBoot实现自动配置原理图解:
1313
@@ -95,7 +95,7 @@ public class ServerProperties {
9595}
9696```
9797
98- # 实现自动配置
98+ ## 实现自动配置
9999
100100实现当某个类存在时,自动配置这个类的bean,并且可以在application.properties中配置bean的属性。
101101
@@ -274,3 +274,43 @@ public class SpringbootDemoApplication {
274274hello.msg =大彬
275275```
276276
277+
278+
279+
280+
281+ ## @Value 原理
282+
283+ @Value 的解析就是在bean初始化阶段。BeanPostProcessor定义了bean初始化前后用户可以对bean进行操作的接口方法,它的一个重要实现类AutowiredAnnotationBeanPostProcessor为bean中的@Autowired 和@Value 注解的注入功能提供支持。
284+
285+
286+
287+ ## 启动过程
288+
289+ 准备Environment——发布事件——创建上下文、bean——刷新上下文——结束。
290+
291+ 构造SpringApplication的时候会进行初始化的工作,初始化的时候会做以下几件事:
292+ 判断运行环境类型,有三种运行环境:NONE 非 web 的运行环境、SERVLET 普通 web 的运行环境、REACTIVE 响应式 web 的运行环境
293+ 加载 spring.factories 配置文件, 并设置 ApplicationContextInitializer
294+ 加载配置文件, 设置 ApplicationListener
295+
296+
297+ SpringApplication构造完成之后调用run方法,启动SpringApplication,run方法执行的时候会做以下几件事:
298+ 构造一个StopWatch,观察SpringApplication的执行
299+ 找出SpringApplicationRunListener,用于监听SpringApplication run方法的执行。监听的过程中会封装SpringApplicationEvent事件,然后使用ApplicationEventMulticaster广播出去,应用程序监听器ApplicationListener会监听到这些事件
300+ 发布starting事件
301+ 加载配置资源到environment,包括命令行参数、application.yml等
302+ 发布environmentPrepared事件
303+ 创建并初始化ApplicationContext,设置environment,加载配置
304+ refresh ApplicationContext
305+
306+ - 设置beanFactory
307+ - 调用BeanFactoryPostProcessors
308+ - 初始化消息源
309+ - 初始化事件广播器(initApplicationEventMulticaster)
310+ - 调用onRefresh()方法,默认是空实现
311+ - 注册监听器
312+ - 实例化non-lazy-init单例
313+ - 完成refresh
314+ - 发布ContextRefreshedEvent事件
315+
316+ 发布started事件,启动结束
You can’t perform that action at this time.
0 commit comments