据说这个方法里面调用了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. minio上传大于30M文件失败

    minio上传30M文件失败.提示失败或者进度不动.翻查手册发现并未限速.原因是使用了nginx做代理.上传超过30M大的客户端文件无法正常上传,修改了下nginx的配置,就可以了. 加上client ...

  2. js_倒计时去执行函数或则跳转页面

    js_倒计时去执行函数或则跳转页面: var wait = 5; $(document).ready(function () { returnPage(); }); function returnPa ...

  3. 两年.net码农总结

    一直都是在博客园看文章,几乎每个两三天都会来,不管是看技术分享还是看经验总结,我觉得这真是个好地方. 工作两年,24.5岁,目前达到8.5K(即10W)的.net web. 文章水平不好,各位见谅了, ...

  4. I2C和SPI总线对比

    1 iic总线不是全双工,2根线SCL SDA.spi总线实现全双工,4根线SCK CS MOSI MISO 2 iic总线是多主机总线,通过SDA上的地址信息来锁定从设备.spi总线只有一个主设备, ...

  5. centos7 redmine安装过程

     mysql安装配置   redmine 部署过程 redmin官方文档写的太烂加上不熟悉ruby搞了半天,回到家后觉得还是记录下好,希望可以帮助有需要的人,少走弯路. 版本说明 下面的版本很重要re ...

  6. bzoj4802 欧拉函数(附Millar-Rabin和Pollard-Rho讲解)

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4802 [题解] 参考:http://www.matrix67.com/blog/archiv ...

  7. Git之创建仓库并上传/更新项目版本

    1.Git配置 使用Git的第一件事就是设置你的名字和email,这些就是你在提交commit时的签名,每次提交记录里都会包含这些信息.使用git config命令进行配置: $ git config ...

  8. vue单页应用中 返回列表记住上次滚动位置、keep-alive缓存之后更新列表数据 那点事

    实践场景需求 产品列表中,滚动到一定位置的时候,点击查看产品信息,后退之后,需要回到原先的滚动位置,这是常见的需求 所有页面均在router-view中,暂时使用了keep-alive来缓存所有页面, ...

  9. mysql数据库导出excel xml等格式文件

    http://jingyan.baidu.com/article/ac6a9a5e43a62e2b653eac83.html

  10. tomcat顺序图摘要

    1.Connector 处理一次请求顺序图 2.Context 和 wrapper 的处理请求时序图 3. 参考: https://www.ibm.com/developerworks/cn/java ...