Spring源码阅读--AbstractApplicationContext refresh()方法调用
来源:互联网 发布:网络专科文凭有用吗 编辑:程序博客网 时间:2024/05/18 00:22
Spring初始化Ioc容器很重要的一个方法是由ApplicationContext子接口ConfigurableApplicationContext提供的refresh(),这个方法的作用是创建加载Spring容器配置(包括.xml配置,property文件和数据库模式等)。下面是各个refresh()调用的各个方法的作用解析:
@Overridepublic void refresh() throws BeansException, IllegalStateException {synchronized (this.startupShutdownMonitor) {// Prepare this context for refreshing.prepareRefresh();// Tell the subclass to refresh the internal bean factory.//主要是创建beanFactory,同时加载配置文件.xml中的beanDefinition//通过String[] configLocations = getConfigLocations()获取资源路径,然后加载beanDefinitionConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();// Prepare the bean factory for use in this context.//给beanFactory注册一些标准组建,如ClassLoader,StandardEnvironment,BeanProcessprepareBeanFactory(beanFactory);try {// Allows post-processing of the bean factory in context subclasses.//提供给子类实现一些postProcess的注册,如AbstractRefreshableWebApplicationContext注册一些Servlet相关的//postProcess,真对web进行生命周期管理的Scope,通过registerResolvableDependency()方法注册指定ServletRequest,HttpSession,WebRequest对象的工厂方法postProcessBeanFactory(beanFactory);// Invoke factory processors registered as beans in the context.//调用所有BeanFactoryProcessor的postProcessBeanFactory()方法invokeBeanFactoryPostProcessors(beanFactory);// Register bean processors that intercept bean creation.//注册BeanPostProcessor,BeanPostProcessor作用是用于拦截Bean的创建registerBeanPostProcessors(beanFactory);// Initialize message source for this context.//初始化消息BeaninitMessageSource();// Initialize event multicaster for this context.//初始化上下文的事件多播组建,ApplicationEvent触发时由multicaster通知给ApplicationListenerinitApplicationEventMulticaster();// Initialize other special beans in specific context subclasses.//ApplicationContext初始化一些特殊的beanonRefresh();// Check for listener beans and register them.//注册事件监听器,事件监听Bean统一注册到multicaster里头,ApplicationEvent事件触发后会由multicaster广播registerListeners();// Instantiate all remaining (non-lazy-init) singletons.//非延迟加载的单例Bean实例化finishBeanFactoryInitialization(beanFactory);// Last step: publish corresponding event.finishRefresh();}catch (BeansException ex) {logger.warn("Exception encountered during context initialization - cancelling refresh attempt", ex);// Destroy already created singletons to avoid dangling resources.destroyBeans();// Reset 'active' flag.cancelRefresh(ex);// Propagate exception to caller.throw ex;}}}
0 0
- Spring源码阅读--AbstractApplicationContext refresh()方法调用
- AbstractApplicationContext.refresh()
- Spring源码学习--AbstractApplicationContext(八)
- Spring源码学习——AbstractApplicationContext
- Spring的refresh()方法调用过程
- spring初始化refresh()方法中obtainFreshBeanFactory()源码走读。
- spring 容器的refresh方法
- AbstractApplicationContext
- AbstractApplicationContext
- 浅析Spring IoC源码(十一)Spring refresh()方法解析之一
- 浅析Spring IoC源码(十一)Spring refresh()方法解析后记2
- spring源码阅读1——环境搭建&阅读方法
- Spring源码由浅入深系列三 refresh
- 浅析Spring IoC源码(三)分析refresh()方法前的准备篇(一)
- Spring源码解析之零 ------ 容器初始化过程(refresh()方法)概要
- 做一个合格的程序猿之浅析Spring IoC源码(十一)Spring refresh()方法解析之一
- 做一个合格的程序猿之浅析Spring IoC源码(十一)Spring refresh()方法解析后记1
- 做一个合格的程序猿之浅析Spring IoC源码(十一)Spring refresh()方法解析后记2
- scrapy-mysql
- ios7.0 横竖屏幕限制
- android利用数字证书对程序签名
- 攀爬跑酷
- Githud纤细教程
- Spring源码阅读--AbstractApplicationContext refresh()方法调用
- Codeforces Round #278 (Div. 2) A Giga Tower
- 网络经济——消费习惯之争
- 第十三周项目 4 数组的排序(选择排序)
- 网络知识之网关理解
- C++模板:辨别函数类型
- CMCC-EDU 登陆过程分析 图文详解
- thinkpad t440p无线网卡内核修复方案
- 互联网公司招聘启事的正确阅读方式