Spring IOC 初始化刷新流程一:prepareRefresh()
2023-09-27 14:23:43 时间
Spring IOC 初始化刷新流程:https://www.cnblogs.com/jhxxb/p/13609289.html
方法源码
public abstract class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext { protected void prepareRefresh() { // Switch to active. // 记录容器启动时间,然后设立对应的标志位 this.startupDate = System.currentTimeMillis(); this.closed.set(false); this.active.set(true); // 打印 info 日志:开始刷新容器 if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) { logger.trace("Refreshing " + this); } else { logger.debug("Refreshing " + getDisplayName()); } } // Initialize any placeholder property sources in the context environment. // 扩展方法,由子类去实现,可以在验证之前,为系统属性设置一些值 // 这里是 AnnotationConfigApplicationContext,什么都没做 initPropertySources(); // Validate that all properties marked as required are resolvable: see ConfigurablePropertyResolver#setRequiredProperties // 这里有两步,getEnvironment(),然后验证系统环境中是否有 RequiredProperties 参数值。其实就干了一件事,验证是否存在必须的属性 getEnvironment().validateRequiredProperties(); // Store pre-refresh ApplicationListeners... // 存储容器预刷新的 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, to be published once the multicaster is available... // 初始化容器,用于装载早期的一些事件 this.earlyApplicationEvents = new LinkedHashSet<>(); }
getEnvironment()
顶层接口位于:EnvironmentCapable,有如下实现,ConfigurableApplicationContext 是接口,所以容器的实现只有 AbstractApplicationContext
相关文章
- Spring声明式事务详解
- 一文详解RocketMQ-Spring的源码解析与实战
- Spring实战学习笔记之SpEL表达式
- Spring入门详细教程(一)
- spring boot整合 spring security之自定义登录页面(2)
- Spring的优缺点
- Spring MVC源码(二) ----- DispatcherServlet 请求处理流程 面试必问
- Spring Cloud 升级最新 Greenwich 版本,舒服了~
- Spring中默认bean名称的生成策略/方式修改
- activiti自己定义流程之Spring整合activiti-modeler实例(一):环境搭建
- Spring AOP 代理创建流程与执行流程
- eclipse安装spring boot插件spring tool suite
- Spring Boot 集成日志logback + 控制台打印SQL
- Spring 声明式事务管理
- Spring Cloud 新一代Web框架微服务翘楚(一)
- [Spring Framework]AOP工作流程
- 利用Spring的AbstractRoutingDataSource解决多数据源的问题【代码手动切换,非AOP】
- Spring Boot使用Spring Security POST无法访问解决方案
- spring-boot-starter-data-jpa 解析
- spring mvc@ModelAttribute与@SessionAttributes的执行流程