备战面试日记(4.2.3)- (框架.Spring【三】之Spring IOC 源码prepareRefresh())

本人本科毕业,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<>();
}
全部评论

相关推荐

11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务