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应用中 ...
随机推荐
- Linux下压缩工具gzip和归档工具tar及其实战shell应用
Linux下压缩工具gzip和归档工具tar及其实战shell应用 第一章:gzip的使用技巧 gzip [option]... file... -d: 解压缩,相当于gunzip; -# ...
- SQLServer常用快捷键汇总
菜单激活键盘快捷键 操作 SQL Server 2017 SQL Server 2008 R2 移到 SQL Server Management Studio 菜单栏 Alt Alt 激活工具组件的菜 ...
- ulimit 更改 gcc升级 查看显卡状态命令
一.更改ulimit: vim /etc/security/limits.conf 在文件最下方添加以下内容 * soft nofile 65536* hard nofile 65536 二. gcc ...
- Java命令行传参
目的: 在运行一个程序时候再传递给它消息,这就需要传递命令参数给main()函数实现:即main()方法可以传递数据 例: public class demo{ public static void ...
- 06webpack-- html-webpack-plugin的2个作用
<!-- 15 html-webpack-plugin的2个作用 下载 cnpm i html-webpack-plugin -D 作用在==>内存中生成页面 在webpack中 导入在内 ...
- selenium 2定位方式实例
#########百度输入框的定位方式########## #通过id方式定位 browser.find_element_by_id("kw").send_keys("s ...
- pikachu 文件包含,上传,下载
一.文件包含 1.File Inclusion(local) 我们先测试一下,选择kobe然后提交 发现url出现变化 可以猜测此功能为文件包含,包含的文件为 file1.php,所以我在此盘符的根目 ...
- nginx 缓存配置
nginx 缓存是可以将远程服务器上的内容缓存到本地,可以设置缓存大小,缓存时间,缓存目录等等 具体配置如下 proxy_cache_path /home/http/cache/ levels=: k ...
- Windows/Linux下jdk环境配置
Windows 7下: Windows7 x64位系统 安装好java 1.点击开始菜单选择计算机选项右键选择属性选项 即可 2.然后在属性界面点击如图所示的高级系统设置选项 3.打开系统属性界面然后 ...
- pcp 基本使用
pcp 是一款强大的metrics 分析工具,包含了比较完整的指标分析工具链,同时也已经包含了好多pmdas 核心组件 参考架构 安装 centos yum install -y pcp 启动 sys ...