spring源码-1.容器刷新前准备

骑猪看日落 2024-04-17 06:01 182阅读 0赞

这一节我们来看一下prepareRefresh方法都做了什么。
首先看一下这个方法的源码:

  1. protected void prepareRefresh() {
  2. //记录开始时间
  3. this.startupDate = System.currentTimeMillis();
  4. //设置状态
  5. this.closed.set(false);
  6. this.active.set(true);
  7. //这里是一个空方法,留给子类进行定制化处理
  8. initPropertySources();
  9. //校验必要的属性
  10. getEnvironment().validateRequiredProperties();
  11. //初始化earlyApplicationListeners,并将所有的Listeners放进去
  12. if (this.earlyApplicationListeners == null) {
  13. this.earlyApplicationListeners = new LinkedHashSet<>(this.applicationListeners);
  14. }
  15. else {
  16. //重置earlyApplicationListeners
  17. this.applicationListeners.clear();
  18. this.applicationListeners.addAll(this.earlyApplicationListeners);
  19. }
  20. //初始化一个earlyApplicationEvents
  21. this.earlyApplicationEvents = new LinkedHashSet<>();
  22. }

prepareRefresh方法比较简单,除了设置状态和校验一些必要的属性,还初始化了earlyApplicationListeners和earlyApplicationEvents,这两个Set是用来存放项目中定义的监听器和监听事件的。

发表评论

表情:
评论列表 (有 0 条评论,182人围观)

还没有评论,来说两句吧...

相关阅读