zoukankan      html  css  js  c++  java
  • Spring源码情操陶冶-AbstractApplicationContext#registerBeanPostProcessors

    承接前文Spring源码情操陶冶-AbstractApplicationContext#invokeBeanFactoryPostProcessors

    瞧瞧官方注释

    	/**
    	 * Instantiate and invoke all registered BeanPostProcessor beans,
    	 * respecting explicit order if given.
    	 * <p>Must be called before any instantiation of application beans.
    	 */
    

    实例化并且调用所有的已注册的BeanPostProcessor beans,其实也就是简单的把DefaultListableFactory中的所有为BeanPostProcessor的实现bean类放置于其内部属性beanPostProcessors List集合中。

    直接源码

    protected void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory) {
        //调用的是委托类的registerBeanPostProcessors方法		
        PostProcessorRegistrationDelegate.registerBeanPostProcessors(beanFactory, this);
    	}
    

    间接源码-PostProcessorRegistrationDelegate.registerBeanPostProcessors

    public static void registerBeanPostProcessors(
    			ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) {
    //获取beanFactory中的所有实现BeanPostProcessor接口的bean
    		String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);
    
    		// Register BeanPostProcessorChecker that logs an info message when
    		// a bean is created during BeanPostProcessor instantiation, i.e. when
    		// a bean is not eligible for getting processed by all BeanPostProcessors.
    		int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;
    		//BeanPostProcessorChecker检查类
    		beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount));
    
    		//此处的实现与上节的invokeBeanFactoryPostProcessors方法一致,这里就省略不赘述了
    		List<BeanPostProcessor> priorityOrderedPostProcessors = new ArrayList<BeanPostProcessor>();
    		List<BeanPostProcessor> internalPostProcessors = new ArrayList<BeanPostProcessor>();
    		List<String> orderedPostProcessorNames = new ArrayList<String>();
    		List<String> nonOrderedPostProcessorNames = new ArrayList<String>();
    		/**省略*/
    
    		// Finally, re-register all internal BeanPostProcessors.
    		OrderComparator.sort(internalPostProcessors);
    		//主要是调用此方法将所有的postProcessors按照优先级有序的放置在beanFactory的内部属性beanPostProcessors集合中
    		registerBeanPostProcessors(beanFactory, internalPostProcessors);
    		//增加ApplicationListenerDetector类
    		beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));
    	}
    

    小结

    1. 获取beanFactory中的所有实现postProcessor接口的bean对象按照优先级有序的放置在beanFactory的内部属性beanPostProcessors集合中,但是并没有执行其中的相应公共方法
    2. 新增两个BeanPostProcessor实现类:BeanPostProcessorChecker为首,ApplicationListenerDetector为尾

    下节预告

    Spring源码情操陶冶-AbstractApplicationContext#initMessageSource

  • 相关阅读:
    定理,定律,公理
    逻辑的体系:论据-》论证-〉论点
    深度解读:数学的本质与宇宙万物的关联--数学的本质是一门语言
    第一性原理的钥匙—逻辑奇点
    系统论的两个方向:系统分析与系统构建
    系统
    科学思考
    系统思考-使用系统论构建系统
    系统论是大尺度的还原论的时空思考-系统论是宏观上的还原论
    思考的几种形式
  • 原文地址:https://www.cnblogs.com/question-sky/p/6825588.html
Copyright © 2011-2022 走看看