据说这个方法里面调用了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()研究的更多相关文章

  1. Spring源码情操陶冶-AbstractApplicationContext#obtainFreshBeanFactory

    前言-阅读源码有利于陶冶情操,本文承接前文Spring源码情操陶冶-AbstractApplicationContext 约束: 本文指定contextClass为默认的XmlWebApplicati ...

  2. spring启动component-scan类扫描加载过程(转)

    文章转自 http://www.it165.net/pro/html/201406/15205.html 有朋友最近问到了 spring 加载类的过程,尤其是基于 annotation 注解的加载过程 ...

  3. ApplicationListener<ContextRefreshedEvent>接口,Spring启动后获取所有拥有特定注解的Bean

    最近项目中遇到一个业务场景,就是在Spring容器启动后获取所有的Bean中实现了一个特定接口的对象,第一个想到的是ApplicationContextAware,在setApplicationCon ...

  4. Spring启动后获取所有拥有特定注解的Bean,注解的属性值

    最近项目中遇到一个业务场景,就是在Spring容器启动后获取所有的Bean中实现了一个特定接口的对象,第一个想到的是ApplicationContextAware,在setApplicationCon ...

  5. spring 启动异常Failed to read candidate component class

    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: ...

  6. 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 今天把在线聊天室代码改了下 ...

  7. spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情

    <spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情> <服务网关zu ...

  8. Spring启动时获取自定义注解的属性值

    1.自定义注解 @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documen ...

  9. spring启动异步线程

    大纲: spring启动异步线程 spring配置线程池 一.spring启动异步线程 spring启动异步线程方法就是在方法上加上注解@Async,然后启动类或配置类上加上注解@EnableAsyn ...

随机推荐

  1. Study 3 —— 表格

    表格基本格式: <table> <tr> <td></td> <td></td> </tr> <tr> ...

  2. java AOP使用配置项来进行注入实践

    java AOP使用注解@annotation方式实践 场景: 在目标方法前面和后面执行通知方法 目标类 @Component public class Play { public void watc ...

  3. 向GitHub上上传代码(转)

    使用git将项目上传到github(最简单方法)   首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下 ...

  4. Nginx 内核优化

    内核参数的优化示例: /etc/sysctl.conf net.ipv4.tcp_max_tw_buckets = // timewait的数量,默认是180000. net.ipv4.ip_loca ...

  5. [CERC2016]机棚障碍 Hangar Hurdles(kruskal重构树+树上倍增)

    题面 \(solution:\) 某蒟蒻的心路历程: 这一题第一眼感觉很奇怪 带障碍物的图,最大的集装箱? 首先想到的就是限制我集装箱大小条件的是什么: 如果我要在某一个点上放一个集装箱且使它最大, ...

  6. JavaScript学习 - 基础(二) - 基础类型/类型转换

    基础类型 - 数字类型(Number) 1.最基本的数据类型 2.不区分整型数值和浮点型数值 3.所有数字采用64位浮点格式存储,相当于Java和C语言中double格式 4.能表示的最大值 +- 1 ...

  7. Jetson tk1 安装 Intel 7260 无线网卡驱动

    Jseton TK1上没有集成的无线网卡,开发板上有一个mini pci-e接口,可以插入Intel 7260这款继承了wifi和蓝牙功能的无线网卡: 该网卡实物如下图,在淘宝和Amazon上都可以买 ...

  8. root权限使用vim不能修改权限

    1.背景: 有时候我们会发现使用root权限不能修改某个文件,大部分原因是曾经使用chattr将文件锁定了 2.chattr命令介绍: 用来改变文件属性,能防止root用户误删文件等作用 3.使用方法 ...

  9. 017_nginx重定向需求

    重定向的各种需求 需求一. 前端同事需要把特定的url进行重定向,实现如下: location / { root /data/base.apiportal_opsweb; index index.ht ...

  10. TOMCAT服务器配置域名

    最近做了个网站,用的是web'服务器是tomcat,框架式SpringMVC,功能做好后,就准备上线使用了, 手上已经有域名以及一台服务器,已经绑定好ip了,剩下的也就是配置Tomcat了,比较简单, ...