SpringBoot运行源码分析:Spring应用上下文刷新

Spring应用上下文的刷新

Spring 应用上下文的刷新,是通过调用 SpringApplication 中的 refreshContext 方法来完成的。SpringApplication 中 refreshContext 方法相关代码如下。

private void refreshContext(ConfigurableApplicationContext context) {
//调用 refresh 方法
refresh(context);
if (this.registerShutdownHook) {
try
//注册 shutdownHook 线程, 实现销毁时的回调
context . registerShutdownHook();
} catch (AccessControlException ex) {
//在某些环境中不允许使用,会报出此异常,但此处并无处理操作
protected void refresh(ApplicationContext applicationContext) {
Assert. isInstanceOf(AbstractApplicationContext. class, applicationContex
t);
((AbstractAppl icationContext) applicat ionContext) .refresh();
}
}

其中 refresh 方法调用的是
AbstractApplicationContext 中的 refresh 方法,该类属于 spring-context 包。AbstractApplicationContext 的 refresh 方法更 多的是 Spring 相关的内容,这里我们通过 refresh 方法的顶层代码了解该方法都做了些什么,不过多深入 Spring 内部进行讲解。

blic void refresh() throws BeansException, IllegalStateException {
//整个过程同步处理
s
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值