spring bean初始化过程
2017-06-26 17:56
387 查看
SpringBean 初始化过程 ClassPathXmlApplication reflsh() //记录执行时间 prepareRefresh(); //主要是创建beanFactory(DefaultListableBeanFactory),同时加载配置文件.xml中的beanDefinition //通过String[] configLocations = getConfigLocations()获取资源路径, //加载beanDefinition(XmlBeanDefinitionReader.loadBeanDefinitions(configLocations)) ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); //准备beanFactory //设置默认的组件(classLoader) prepareBeanFactory(beanFactory); try { //提供给子类实现一些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. //初始化消息Bean initMessageSource(); // Initialize event multicaster for this context. //初始化上下文的事件传播组建,ApplicationEvent触发时由multicaster通知给ApplicationListener initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses. //ApplicationContext初始化一些特殊的bean onRefresh(); // 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) { // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset 'active' flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; }
相关文章推荐
- spring中bean初始化过程
- Spring核心学习(6)引用ApplicationContext-包装Bean的初始化过程,对应用透明
- Springbean初始化过程
- Spring 初始化bean过程图解
- Spring Bean初始化过程
- Spring4.3.x 容器中bean的创建过程(4)—— 执行bean的初始化方法
- Spring源码分析:非懒加载的单例Bean初始化过程(上)
- spring中bean的初始化过程
- CGLIB(Enhancer/FastClass/BulkBean) & spring容器初始化过程
- Spring4.3.x 容器中bean的创建过程(3)—— 初始化bean的属性值
- Spring原理(一)IoC容器的初始化过程之BeanFactory
- spring笔记6 容器加载过程、bean初始化
- 关于Spring 中初始化bean的过程
- 模拟Spring中applicationContext.xml配置文件初始化bean的过程
- 【Spring源码分析】非懒加载的单例Bean初始化过程(上篇)
- 【Spring源码分析】非懒加载的单例Bean初始化过程(下篇)
- Spring中Bean初始化过程
- Spring源码分析:非懒加载的单例Bean初始化过程(下)
- Spring中Bean的初始化过程
- spring容器初始化,bean加载生成过程,源码解析学习