spring容器的功能扩展
容器的扩展功能主要实现为:
org.springframework.context.support.AbstractApplicationContext.refresh()
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// 准备刷新的上下文环境
// Prepare this context for refreshing.
prepareRefresh();
// 初始化BeanFactory,并进行xml文件读取
// Tell the subclass to refresh the internal bean factory.
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
// 对BeanFactory进行各种功能填充
// Prepare the bean factory for use in this context.
prepareBeanFactory(beanFactory);
try {
// 子类覆盖方法做额外的处理
// Allows post-processing of the bean factory in context subclasses.
postProcessBeanFactory(beanFactory);
// 激活各种BeanFactory处理器
// Invoke factory processors registered as beans in the context.
invokeBeanFactoryPostProcessors(beanFactory);
// 注册拦截bean创建的bean处理器,这里只是注册,真正的调用时在getBean时候
// Register bean processors that intercept bean creation.
registerBeanPostProcessors(beanFactory);
// 为上下文初始化Message源,即不同语言的消息体,国际化处理
// Initialize message source for this context.
initMessageSource();
// 初始化应用消息广播器,并放入ApplicationEventMulticaster中
// Initialize event multicaster for this context.
initApplicationEventMulticaster();
// 留给子类来初始化其他的bean
// Initialize other special beans in specific context subclasses.
onRefresh();
// 在所有注册的bean中查找listener bean,注册到消息广播器中
// Check for listener beans and register them.
registerListeners();
// 初始化剩下的单实例(非延迟加载的)
// Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory);
// 完成刷新过程,通知生命周期处理器lifecycleProcessor刷新过程,同时发出ContextRefreshEvent通知别人
// 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源码深度解析
spring容器的功能扩展的更多相关文章
- Spring源码学习(6)——容器的功能扩展
之前的随笔中借BeanFactory介绍了bean的解析和加载的完整过程,实际上,除了BeanFactory,spring还提供了一种功能更加强大的容器:ApplicationContext Appl ...
- Spring源码分析(十九)容器的功能扩展概览
摘要: 本文结合<Spring源码深度解析>来分析Spring 5.0.6版本的源代码.若有描述错误之处,欢迎指正. 经过前面几章的分析,相信大家已经对 Spring 中的容器功能有了简单 ...
- spring源码深度解析-2功能扩展
容器功能的扩展ApplicationContext用于扩展BeanFactory中现有的功能.究竟多出了哪些功能,进一步探索.写法上:BeanFactory bf = new XmlBeanFacto ...
- Spring 系列教程之容器的功能
Spring 系列教程之容器的功能 经过前面几章的分析,相信大家已经对 Spring 中的容器功能有了简单的了解,在前面的章节中我们一直以 BeanFacotry 接口以及它的默认实现类 XmlBea ...
- Spring核心技术(七)——Spring容器的扩展
本文将讨论如何关于在Spring生命周期中扩展Spring中的Bean功能. 容器的扩展 通常来说,开发者不需要通过继承ApplicationContext来实现自己的子类扩展功能.但是Spring ...
- spring4.1.8扩展实战之六:注册bean到spring容器(BeanDefinitionRegistryPostProcessor接口)
本章是<spring4.1.8扩展实战>系列的第六篇,目标是学习如何通过自己写代码的方式,向spring容器中注册bean: 原文地址:https://blog.csdn.net/boli ...
- 从Spring容器的角度理解Dubbo扩展点的加载时机
对于Dubbo提供的扩展点,主程序执行的过程中并没有显示调用加载的过程,无论是自激活的Filter还是自适应的ThreadPool.那么这样的扩展点在程序运行的哪个节点调用的呢?跟踪之前性能监控扩展点 ...
- spring4.1.8扩展实战之四:感知spring容器变化(SmartLifecycle接口)
本章是<spring4.1.8扩展实战>的第四篇,如果业务上需要在spring容器启动和关闭的时候做一些操作,可以自定义SmartLifecycle接口的实现类来扩展,本章我们通过先分析再 ...
- Spring是什么,Spring容器提供了那些功能,Spring的工作机制
spring是什么 spring 是一个轻型的容器,是J2EE规范的轻量级实现,可以一站式开发,其中提供了,bean工厂,用以构造我们需要的Model ,spring 是非侵入式的,spring应用中 ...
随机推荐
- RequestsDependencyWarning: urllib3 (1.25.7) or chardet (2.2.1) doesn't match a supported version
/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.7 ...
- linux下网卡捆绑
七种bond模式说明:mod=0:(balance-rr) Round-robin policy(平衡抡循环策略)mod=1:(active-backup) Active-backup policy( ...
- Rust中的Rc--引用计数智能指针
大部分情况下所有权是非常明确的:可以准确的知道哪个变量拥有某个值.然而,有些情况单个值可能会有多个所有者.例如,在图数据结构中,多个边可能指向相同的结点,而这个结点从概念上讲为所有指向它的边所拥有.结 ...
- CMS垃圾收集器深入详解
上一次[https://www.cnblogs.com/webor2006/p/11048407.html]对安全点和安全区进行了理论化的了解,接下来继续对CMS进行其它理论的了解,还是纯理论!!坚持 ...
- SpringBoot整合easyexcel实现Excel的导入与导出
导出 在一般不管大的或者小的系统中,各家的产品都一样,闲的无聊的时候都喜欢让我们这些程序员导出一些数据出来供他观赏,非说这是必须需求,非做不可,那么我们就只能苦逼的哼哧哼哧的写bug喽. 之前使用PO ...
- 张兴盼-201871010131《面向对象程序设计(Java)》第七周学习总结
张兴盼-201871010131<面向对象程序设计(Java)>第七周学习总结 项目 内容 这个作业属于哪个课程 http://www.cnblogs.com/nwnu-daizh/ 这个 ...
- 网络服务—NFS
什么是NFS ? NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操作 ...
- 代码审计-sha()函数比较绕过
<?php $flag = "flag"; if (isset($_GET['name']) and isset($_GET['password'])) { var_dump ...
- Visual Assist X(网上收集,仅供学习与研究,支持正版)
Visual AssistX是一款非常好的Microsoft Visual Studio插件,它可以完全集成到您的Microsoft开发环境中,升级了您的IDE, 在不改变编程习惯的同时就可以感受到V ...
- Codeforces Round #609 (Div. 2) 题解
Equation Modulo Equality Long Beautiful Integer Domino for Young K Integers Equation \[ Time Limit: ...