Spring-Spring容器启动各项操作窥探(AbstractApplicationContext#refesh()执行逻辑分析)
2014-04-11 15:18
736 查看
public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { // Prepare this context for refreshing. prepareRefresh(); // Tell the subclass to refresh the internal bean factory. /** *初始化BeanFactory.根据配置文件实例化BeanFactory,getBeanFactory方法由具体子类实现。在这一步里,Spring *将配置文件的信息装入到容器的Bean定义注册表(BeanDefinitionRegistry)中,但此时Bean还未初始化。 */ ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. prepareBeanFactory(beanFactory); try { // Allows post-processing of the bean factory in context subclasses. postProcessBeanFactory(beanFactory); /** *调用工厂后处理器:根据反射机制从BeanDefinitionRegistry中找出所有BeanFactoryPostProcessor *类型的Bean,并调用其postProcessBeanFactory()接口方法。 */ invokeBeanFactoryPostProcessors(beanFactory); /** *注册Bean后处理器:根据反射机制从BeanDefinitionRegistry中找出所有BeanPostProcessor *类型的Bean,并将它们注册到容器Bean后处理器的注册表中 **/ registerBeanPostProcessors(beanFactory); // 初始化消息源:初始化容器的国际化信息资源 initMessageSource(); // 初始化应用上下文事件广播器. initApplicationEventMulticaster(); /** *初始化其它特殊的Bean:由具体子类实现;这是一个钩子方法,子类可以借助这个方法执行一些特殊的 *操作:如AbstractRefreshableWebApplicationContext就使用该方法执行初始化ThemeSource的操作 **/ onRefresh(); // 注册事件监听器 registerListeners(); // 初始化所有单实例的Bean(lazy-init的除外),初始化Bean后将它们放入Spring容器的缓存中; finishBeanFactoryInitialization(beanFactory); // 完成刷新并发布容器刷新事件:创建上下文刷新事件,事件广播器负责将这些事件广播到各个注册的事件监听器中。 finishRefresh(); } catch (BeansException ex) { // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset 'active' flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } } }
相关文章推荐
- Spring boot源码分析-AnnotationConfigApplicationContext非web环境下的启动容器(2)
- Spring启动研究2.AbstractApplicationContext.obtainFreshBeanFactory()研究
- 启动tomcat的时候报错:org/springframework/context/support/AbstractRefreshableConfigApplicationContext
- Spring boot源码分析-AnnotationConfigEmbeddedWebApplicationContext默认web环境下的启动容器(3)
- Spring 为了将spring容器和对象的创建在服务器启动时创建(并且只创建一次),将其放在servletContext的监听器内执行。参数名contextConfigLocation哪里找?
- spring boot, 容器启动后执行某操作
- (项目)Initializing Spring root WebApplicationContext ,服务器启动到这里就无法继续执行
- Spring ApplicationContext 容器 FileSystemXmlApplicationContext
- Spring源码情操陶冶-AbstractApplicationContext#finishBeanFactoryInitialization
- Spring 学习-------WebApplication (web 容器)启动
- Spring 2.0.8 和 2.5 applicationContext.xml 头文件写法 Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans'
- Spring中操作applicationContext.xml
- 从源码看spring applicationContext在web容器中加载过程
- spring 的启动 之加载文件 applicationContext.xml
- spring boot: Bean的初始化和销毁 (一般注入说明(三) AnnotationConfigApplicationContext容器 JSR250注解)
- spring.net 框架分析(二)IApplicationContext
- Spring源码分析1 — 容器启动流程
- 四 spring 源码分析--- 容器启动 时序图
- Spring源码情操陶冶-AbstractApplicationContext#postProcessBeanFactory