zoukankan      html  css  js  c++  java
  • 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();

  • 相关阅读:
    ZR#330. 【18 提高 3】矿石(容斥)
    牛客NOIP提高组R1 C保护(主席树)
    BZOJ1026: [SCOI2009]windy数(数位dp)
    AtCoderBeginnerContest109题解
    BZOJ3679: 数字之积(数位dp)
    牛客NOIP普及组R1 C括号(dp)
    牛客NOIP提高组R1 A中位数(二分)
    BZOJ1576: [Usaco2009 Jan]安全路经Travel(最短路 并查集)
    ZRDay6A. 萌新拆塔(三进制状压dp)
    Python 入门教程 10 ---- Student Becomes the Teacher
  • 原文地址:https://www.cnblogs.com/heben/p/7048002.html
Copyright © 2011-2022 走看看