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应用中 ...
随机推荐
- modbus_tk模块
modbus_tk模块 通过modbus-RTU 读取地址,调用后返回反馈数值和故障信息. modbus_tk模块安装 pip install pymodbus_tk 下面代码功能:读取地址为0x42 ...
- django-manage.py参数
cleanup--从数据库中删除旧数据 compilemessages--将.po文件编译为.mo以与gettext一起使用 createcachetable--为SQL缓存后端创建表 create ...
- JS中的实例方法、静态方法、实例属性、静态属性
一.静态方法与实例方法的例子: 我们先来看一个例子来看一下JS中的静态方法和实例方法到底是什么? 静态方法: function A(){} A.col='red' //静态属性 A.sayMeS=f ...
- JS三座大山再学习 ---- 异步和单线程
本文已发布在西瓜君的个人博客,原文传送门 前言 写这一篇的时候,西瓜君查阅了很多资料和文章,但是相当多的文章写的都很简单,甚至互相之间有矛盾,这让我很困扰:同时也让我坚定了要写出一篇好的关于JS异步. ...
- nginx源码安装与使用
[root@localhost ~]# yum -y install pcre-devel zlib-devel openssl openssl-devel gcc* [root@localhost ...
- [笔记] nice-upload 与 nice-static-server
1.request 支持流模式,管道流pipe,抓取图片并保存就很方便了 request('https://s.gravatar.com/avatar/184a1f14c759795b94ae1d01 ...
- 【转】机器学习实战之K-Means算法
一,引言 先说个K-means算法很高大上的用处,来开始新的算法学习.我们都知道每一届的美国总统大选,那叫一个竞争激烈.可以说,谁拿到了各个州尽可能多的选票,谁选举获胜的几率就会非常大.有人会说,这跟 ...
- Tomcat服务部署与Nginx负载均衡配置
一.中间键产品介绍 目前来说IBM的WebSphere,Oracle的Weblogic占据了市场上java语言Web站点的部分份额,该两种软件都是商业化的软件,由于性能优越,可靠性高等优点应用于大型互 ...
- [LeetCode] 829. Consecutive Numbers Sum 连续数字之和
Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers? ...
- find square root
public class Solution { public static void main(String[] args) { Scanner ip = new Scanner(System.in) ...