spring源码-4-applicationContext(环境上下文)
来源:互联网 发布:花千骨衣服淘宝 编辑:程序博客网 时间:2024/06/05 07:43
ApplicationContext applicationContext= new ClassPathXmlApplicationContext("application.xml");
1. ClassPathXmlApplication也是beanFactory的一个实现
//构造方法public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) throws BeansException { super(parent); setConfigLocations(configLocations); //设置资源路径 if (refresh) { refresh(); //刷新上下文 填充功能 } }
2.. AbstractRefreshableConfigApplicationContex.设置并解析资源t
//为applicationContext 指定资源路径public void setConfigLocations(String... locations) { if (locations != null) { Assert.noNullElements(locations, "Config locations must not be null"); this.configLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { this.configLocations[i] = resolvePath(locations[i]).trim(); //解析指定的资源 PropertyResolver } } else { this.configLocations = null;
3. AbstractApplicationContext 填充上下文环境功能
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 ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. //填充beanFacoty classLoader propertyEditor等 prepareBeanFactory(beanFactory); try { // Allows post-processing of the bean factory in context subclasses. //可以实现此类 重写该方法提供特殊的额外处理 postProcessBeanFactory(beanFactory); // Invoke factory processors registered as beans in the context. // 激活beanFacoty invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation. //注册beanFacoty registerBeanPostProcessors(beanFactory); // Initialize message source for this context. //为上下文初始化message资源 initMessageSource(); // Initialize event multicaster for this context. initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses. //可以实现此类 进行特殊的初始化 onRefresh(); // Check for listener beans and register them. //注册所有的监听器 registerListeners(); // Instantiate all remaining (non-lazy-init) singletons. //初始化所有非 lazy-init 的单例 finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. //1.完成刷新过程 clearResourceCaches(); //2.声明声明周期处理器 getLifecycleProcessor().onRefresh(); //3.发布事件 publishEvent(new ContextRefreshedEvent(this)); finishRefresh(); } catch (BeansException ex) { if (logger.isWarnEnabled()) { 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; } finally { // Reset common introspection caches in Spring's core, since we // might not ever need metadata for singleton beans anymore... resetCommonCaches(); //清除缓存资源 } } }
0 0
- spring源码-4-applicationContext(环境上下文)
- spring boot 源码 ApplicationContext 上下文继承图
- spring 获取上下文applicationContext
- 获取Spring的上下文环境ApplicationContext的方式
- 获取Spring的上下文环境ApplicationContext的方式
- 获取Spring的上下文环境ApplicationContext的方式
- 获取Spring的上下文环境ApplicationContext的方式
- 获取Spring的上下文环境ApplicationContext的方式
- 获取Spring的上下文环境ApplicationContext的方式
- 获取Spring的上下文环境ApplicationContext请注意!!
- 十二种获取Spring的上下文环境ApplicationContext的方法
- 获取Spring的上下文环境ApplicationContext的方式
- 获取Spring的上下文环境ApplicationContext的方式
- Spring +quartz获取ApplicationContext上下文
- 获取Spring上下文即ApplicationContext
- spring源码阅读(五)之ApplicationContext
- Spring源码学习--ApplicationContext(十二)
- Spring 源码分析:ApplicationContext
- xhEditor用法
- 总结
- swustoj dearway's problem(0240)
- Linux ext2, ext3, ext4 文件系统解读[3]
- JDBC的使用(mysql)
- spring源码-4-applicationContext(环境上下文)
- linux下valgrind内存泄露检查
- Ubuntu16.04使用小心得
- JS手撸数据结构系列(二) —— 树的遍历
- 【脚本语言系列】关于Python游戏工具Pygame,你需要知道的事
- css笔记1
- 类和对象
- Kanzi基础---Kanzi的4层框架
- 不一样的师徒盛宴