gball个人知识库
首页
基础组件
基础知识
算法&设计模式
  • 操作手册
  • 数据库
  • 极客时间
  • 每日随笔
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • 画图工具 (opens new window)
关于
  • 网盘 (opens new window)
  • 分类
  • 标签
  • 归档
项目
GitHub (opens new window)

ggball

后端界的小学生
首页
基础组件
基础知识
算法&设计模式
  • 操作手册
  • 数据库
  • 极客时间
  • 每日随笔
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • 画图工具 (opens new window)
关于
  • 网盘 (opens new window)
  • 分类
  • 标签
  • 归档
项目
GitHub (opens new window)
  • 面试

  • 数据库

  • linux

  • node

  • tensorFlow

  • 基础组件

    • mybatis

    • spring

      • 源码分析

        • spring管理bean之间的协同方式
        • Bean的生命周期
      • Conditional 注解
      • IOC
      • spring bean的配置方式
      • springCache配合redis做缓存
      • springIOC
      • spring的refresh方法解析
        • prepareRefresh方法
      • spring模块介绍
      • spring声明式事务失效原因
      • spring事务实战
      • spring语法变化
      • spring的配置信息
      • springBean了解
      • spring的三级缓存如何解决循环依赖
    • 消息队列

    • springboot

    • tomcat如何工作

    • elasticsearch

  • 基础知识

  • 算法与设计模式

  • 分布式

  • 疑难杂症

  • go学习之旅

  • 极客时间

  • 知识库
  • 基础组件
  • spring
ggball
2021-10-08

spring的refresh方法解析

refresh方法会刷新spring的上下文

里面有多达13种方法,一一解析

# prepareRefresh方法

表示在真正做refresh操作之前需要准备做的事情:

  • 设置Spring容器的启动时间,
  • 开启活跃状态,撤销关闭状态,。
  • 初始化context environment(上下文环境)中的占位符属性来源。
  • 验证环境信息里一些必须存在的属性
	/**
	 * Prepare this context for refreshing, setting its startup date and
	 * active flag as well as performing any initialization of property sources.
	 */
	protected void prepareRefresh() {
		// Switch to active.
        // 记录刷新开始时间
		this.startupDate = System.currentTimeMillis();
        // 上下文活动状态设置为开启
		this.closed.set(false);
		this.active.set(true);
		
		if (logger.isDebugEnabled()) {
			if (logger.isTraceEnabled()) {
				logger.trace("Refreshing " + this);
			}
			else {
				logger.debug("Refreshing " + getDisplayName());
			}
		}

		// Initialize any placeholder property sources in the context environment.
        // 初始化上下文中占位符资源
		initPropertySources();

		// Validate that all properties marked as required are resolvable:
        //验证所有标记为必需的属性都是可解析的
		// see ConfigurablePropertyResolver#setRequiredProperties
		getEnvironment().validateRequiredProperties();

		// Store pre-refresh ApplicationListeners...
        // 准备预存的监听器
		if (this.earlyApplicationListeners == null) {
			this.earlyApplicationListeners = new LinkedHashSet<>(this.applicationListeners);
		}
		else {
			// Reset local application listeners to pre-refresh state.
            // 不为空 则监听器重置
			this.applicationListeners.clear();
			this.applicationListeners.addAll(this.earlyApplicationListeners);
		}

		// Allow for the collection of early ApplicationEvents,
        // 为applicaion事件准备的集合
		// to be published once the multicaster is available...
        // 一旦广播器可用,application事件就会被push进去
		this.earlyApplicationEvents = new LinkedHashSet<>();
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
上次更新: 2025/06/04, 15:06:15
springIOC
spring模块介绍

← springIOC spring模块介绍→

最近更新
01
AIIDE
03-07
02
githubActionCICD实战
03-07
03
windows安装Deep-Live-Cam教程
08-11
更多文章>
Theme by Vdoing
总访问量 次 | 总访客数 人
| Copyright © 2021-2025 ggball | 赣ICP备2021008769号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×

评论

  • 评论 ssss
  • 回复
  • 评论 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  • 回复
  • 评论 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  • 回复
×