spring源码学习(八)容器功能拓展
来源:互联网 发布:单片机湿度传感器 编辑:程序博客网 时间:2024/06/05 05:28
我们在项目上常用的一般是ClassPathXmlApplicationContext这个类.
public ClassPathXmlApplicationContext( String[] configLocations, boolean refresh, @Nullable ApplicationContext parent) throws BeansException { super(parent); setConfigLocations(configLocations); if (refresh) { refresh(); } } public void setConfigLocations(@Nullable 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(); } } else { this.configLocations = null; } } @Override 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,进行Xml文件获取 ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. //对BeanFactory进行各种功能填充 prepareBeanFactory(beanFactory); try { // Allows post-processing of the bean factory in context subclasses. //子类覆盖方法做额外处理 postProcessBeanFactory(beanFactory); // Invoke factory processors registered as beans in the context. //激活各种BeanFactory处理器 invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation. //注册拦截Bean创建的Bean处理器,这里只是注册,真正的调用在getBean 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. //留给子类来初始化其他的Bean onRefresh(); // Check for listener beans and register them. //在所有注册的bean中查找Listener bran registerListeners(); // Instantiate all remaining (non-lazy-init) singletons. //初始化剩下的单实例 finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. //完成刷新过程,通知生命周期处理器lifecycleProcessor刷新 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(); } } }
在ClassPathXmlApplicationContext中,做了很多功能上的拓展,增加了spel语言支持,增加了属性注册编辑器,添加了ApplicationContext AwreProcessor处理器,设置依赖忽略和注册依赖,BeanFactory的后处理等,但是核心的东西依然和XmlBeanFactory中相同,所以就不在深入查看源代码了,之后会看一下spring AOP的源码,以后有时间的话会在重新把这里的源码补全。
阅读全文
0 0
- spring源码学习(八)容器功能拓展
- Spring源码阅读(四)—容器的功能拓展ApplicationContext
- spring源码初步学习-容器的功能扩展(ApplicationContext)
- Spring源码学习之容器的功能扩展
- Spring学习(八)Spring IoC容器原理分析
- Spring源码学习--AbstractApplicationContext(八)
- Spring源码解析-容器功能扩展
- 学习tomcat源码(2) 实现servlet容器功能
- STL源码剖析 [容器](八)[priority_queue]
- 【Spring】IOC核心源码学习(二):容器初始化过程
- 【Spring】IOC核心源码学习(二):容器初始化过程
- spring源码初步学习-容器(BeanFactory)基本实现
- Spring源码学习(一):IOC容器初始化
- Spring源码学习之容器篇
- spring源码学习之容器监听器篇
- spring 源码学习-容器初始化-1
- spring 源码学习-容器初始化-2
- nginx 源码学习笔记(八)——基本容器——array数组
- websoket js 客户端发送接收信息
- 去除并替换hselect框右边的箭头的css方法
- 函数的缺省参数与函数的重载
- NULL、0、nullptr 区别分析
- gcc 原子操作
- spring源码学习(八)容器功能拓展
- JVM内存模型
- 【转】linux system()函数的返回值
- echarts的入门使用
- Unity3D-玩家掉血或加血特效
- 前端跨域问题
- Java 基础(11)—— 回调机制
- js 将用连接符连接的英文字符串转换成驼峰命名的三种方法
- 重装纯净官方Win10系统