本人本科毕业,21届毕业生,一年工作经验,简历专业技能如下,现根据简历,并根据所学知识复习准备面试。

记录日期:2022.1.4

大部分知识点只做大致介绍,具体内容根据推荐博文链接进行详细复习。

框架原理 - Spring(三)之Spring IOC 源码prepareRefresh()

AbstractApplicationContext#prepareRefresh()

这一步是创建 Bean 容器前的准备工作,根据源码注解来看,主要作用是准备此上下文以进行刷新,设置其启动日期和活动标志,以及执行属性源的任何初始化。

我们来看一下prepareRefresh()的源码:

protected void prepareRefresh() {
   
    // 记录启动时间,
    // 将 active 属性设置为 true,closed 属性设置为 false,它们都是 AtomicBoolean 类型
    this.startupDate = System.currentTimeMillis();
    this.closed.set(false);
    this.active.set(true);

    //...log

    // 初始化上下文环境中的所有占位符属性源
    // 这是个钩子方法,由子类实现
    initPropertySources();

    // 校验 xml 配置文件
    getEnvironment().validateRequiredProperties();

    // 存储预刷新应用程序***
    if (this.earlyApplicationListeners == null) {
   
        // 为空则初始化
        this.earlyApplicationListeners = new LinkedHashSet<>(this.applicationListeners);
    }
    else {
   
        // 不为空则重置,并添加
        this.applicationListeners.clear();
        this.applicationListeners.addAll(this.earlyApplicationListeners);
    }

    // Allow for the collection of early ApplicationEvents,
    // to be published once the multicaster is available...
    this.earlyApplicationEvents = new LinkedHashSet<>();
}