Spring启动研究2.AbstractApplicationContext.obtainFreshBeanFactory()研究
据说这个方法里面调用了loadBeanDefinitions,据说很重要,并且跟我感兴趣的标签解析有关,所以仔细看看
obtainFreshBeanFactory()这个方法在AbstractApplicationContext中定义如下:
protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
refreshBeanFactory();
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
if (logger.isDebugEnabled()) {
logger.debug("Bean factory for " + getDisplayName() + ": " + beanFactory);
}
return beanFactory;
}
其中refreshBeanFactory()方法也在这方法中,是个抽象方法,所以往回找EmbeddedWebApplicationContext的父类的父类GenericApplicationContext总找到了这个方法的实现:
@Override
protected final void refreshBeanFactory() throws IllegalStateException {
if (this.refreshed) {
throw new IllegalStateException(
"GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once");
}
this.beanFactory.setSerializationId(getId());
this.refreshed = true;
}
但是好像没有我感兴趣的部分,
那看看AbstractApplicationContext类中obtainFreshBeanFactory()方法中ConfigurableListableBeanFactory beanFactory = getBeanFactory()这一段
它也是在GenericApplicationContext实现的:
@Override
public final ConfigurableListableBeanFactory getBeanFactory() {
return this.beanFactory;
}
而这个类的构造方法中初始化了beanFactory:
public class GenericApplicationContext extends AbstractApplicationContext implements BeanDefinitionRegistry {
private final DefaultListableBeanFactory beanFactory;
private ResourceLoader resourceLoader;
private boolean refreshed = false;
/**
* Create a new GenericApplicationContext.
* @see #registerBeanDefinition
* @see #refresh
*/
public GenericApplicationContext() {
this.beanFactory = new DefaultListableBeanFactory();
}
略
感觉没什么内容,就是返回了一个new DefaultListableBeanFactory();
Spring启动研究2.AbstractApplicationContext.obtainFreshBeanFactory()研究的更多相关文章
- Spring源码情操陶冶-AbstractApplicationContext#obtainFreshBeanFactory
前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-AbstractApplicationContext 约束: 本文指定contextClass为默认的XmlWebApplicati ...
- spring启动component-scan类扫描加载过程(转)
文章转自 http://www.it165.net/pro/html/201406/15205.html 有朋友最近问到了 spring 加载类的过程,尤其是基于 annotation 注解的加载过程 ...
- ApplicationListener<ContextRefreshedEvent>接口,Spring启动后获取所有拥有特定注解的Bean
最近项目中遇到一个业务场景,就是在Spring容器启动后获取所有的Bean中实现了一个特定接口的对象,第一个想到的是ApplicationContextAware,在setApplicationCon ...
- Spring启动后获取所有拥有特定注解的Bean,注解的属性值
最近项目中遇到一个业务场景,就是在Spring容器启动后获取所有的Bean中实现了一个特定接口的对象,第一个想到的是ApplicationContextAware,在setApplicationCon ...
- spring 启动异常Failed to read candidate component class
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: ...
- Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans'(转)
Spring启动异常: cvc-elt.1: Cannot find the declaration of element 'beans' 2008-09-07 22:41 今天把在线聊天室代码改了下 ...
- spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情
<spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情> <服务网关zu ...
- Spring启动时获取自定义注解的属性值
1.自定义注解 @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documen ...
- spring启动异步线程
大纲: spring启动异步线程 spring配置线程池 一.spring启动异步线程 spring启动异步线程方法就是在方法上加上注解@Async,然后启动类或配置类上加上注解@EnableAsyn ...
随机推荐
- 微信公众号绑定服务器 Flask版
python 代码 from flask import Flask, request from flask_cors import CORS app = Flask(__name__) app.app ...
- C++ error LNK2001
1.没有函数的实现部分 2.函数的头文件和实现部分不一致 3.缺库LIB.DLL 4.库H文件函数和库体不一致
- python技巧 一等函数
函数在python中作为一等函数,具有以下特点: 1.可以作为参数传递给其他函数 2.作为其他函数的值返回 3.能赋值给变量或数据结构中的元素 4.在运行的时候创建 In [1]: def add(x ...
- Mac下压力测试工具siege
安装: brew install siege 用法: siege -c 并发数 -t 运行测试时间 URL 如: siege -c 1000 -t 5S URL 这里要注意的是-t后面的时间要带单位, ...
- 1.内网ntp服务器的搭建
1.拓扑图
- ROS 错误之 [rospack] Error: package 'beginner_tutorials' not found
ubuntu 下面情况处理 $ cd $gedit .bashrc 再后面加入两行 source /opt/ros/indigo/setup.bash source /home/lv/catkin_w ...
- 【转】linux的特殊符号与正则表达式
[转]linux的特殊符号与正则表达式 第1章 linux的特殊符号 1.1 通配符 * {} 1.1.1 含义 方便查找文件 通配符是用来找文件名字的. 1.1.2 * 通过find 命令找以 . ...
- caffe-win10-cifar10
因为是在win10下安装的GPU版caffe,所以不能直接运行linux里的shell脚本.但是win10自带bash,可以运行.sh文件,网上也有直接下Cygwin和git的.我是下载好git后才知 ...
- 嵌入式系统C编程之错误处理
前言 本文主要总结嵌入式系统C语言编程中,主要的错误处理方式.文中涉及的代码运行环境如下: 一 错误概念 1.1 错误分类 从严重性而言,程序错误可分为致命性和非致命性两类.对于致命性错误,无法执行 ...
- Raw Socket vs Stream Socket vs datagram socket,原始套接字与流式套接字与数据报套接字
https://opensourceforu.com/2015/03/a-guide-to-using-raw-sockets/ In this tutorial, lets take a look ...