刷新IOC容器refreshContextprivatevoidrefreshContext(ConfigurableApplicationContextcontext){if(this.registerShutdownHook){try{context.registerShutdownHook();}catch(AccessControlExceptionex){//在某些环境中不允许。}}//spring的核心源代码refresh((ApplicationContext)context);}==============进入refresh((ApplicationContext)context);@Deprecatedprotectedvoidrefresh(ApplicationContextapplicationContext){Assert.isInstanceOf(ConfigurableApplicationContext.class,applicationContext);刷新((ConfigurableApplicationContext)applicationContext);}protectedvoidrefresh(ConfigurableApplicationContextapplicationContext){applicationContext.refresh();}@Overridepublicfinalvoidrefresh()throwsBeansException,IllegalStateException{try{super.refresh();}catch(RuntimeExceptionex){WebServerwebServer=this.webServer;if(webServer!=null){webServer.stop();}扔前;}}//springioc容器的经典的初始化过程publicvoidrefresh()throwsBeansException,IllegalStateException{Objectvar1=this.startupShutdownMonitor;同步(this.startupShutdownMonitor){StartupStepcontextRefresh=this.applicationStartup.start(“spring.context.refresh”);this.prepareRefresh();ConfigurableListableBeanFactorybeanFactory=this.obtainFreshBeanFactory();this.prepareBeanFactory(beanFactory);尝试{this.postProcessBeanFactory(beanFactory);StartupStepbeanPostProcess=this.applicationStartup.start("spring.context.beans.post-process");this.invokeBeanFactoryPostProcessors(beanFactory);这个.registerBeanPostProcessors(beanFactory);beanPostProcess.end();this.initMessageSource();this.initApplicationEventMulticaster();这个.onRefresh();这个.registerListeners();//实例化容器中所有的组件this.finishBeanFactoryInitialization(beanFactory);这个.finishRefresh();}catch(BeansExceptionvar10){if(this.logger.isWarnEnabled()){this.logger.warn("上下文初始化期间遇到异常-取消刷新尝试:"+var10);}this.destroyBeans();this.cancelRefresh(var10);抛出var10;}最后{this.resetCommonCaches();contextRefresh.end();}}}callRunners(context,applicationArguments)privatevoidcallRunners(ApplicationContextcontext,ApplicationArgumentsargs){//准备runners集合List
