首页 > 移动平台 > 详细

AbstractApplicationContext#refresh方法

时间:2020-11-18 14:40:52      阅读:32      评论:0      收藏:0      [点我收藏+]
    @Override
    public void refresh() throws BeansException, IllegalStateException {
        synchronized (this.startupShutdownMonitor) {
            // Prepare this context for refreshing.
       // 一些初始化,不重要
prepareRefresh(); // Tell the subclass to refresh the internal bean factory.
       // 获取beanFactory, 里面主要是BeanDefinitionMap 和BeanDefinitionName ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. prepareBeanFactory(beanFactory); try { // Allows post-processing of the bean factory in context subclasses.
postProcessBeanFactory(beanFactory);            // Invoke factory processors registered as beans in the context.
          // 调用所有BeanFactory后处理器: BeanFactoryPostProcessor,默认是空的,可以自己定义 invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation.
// 注册bean后处理器,只是注册到beanFactory, 初始化方法前会调用所有的BeanPostProcessor,
// 初始化前后调用postProcessorBeforeInitialization/postProcessorAfterInitialization , aop重点看
registerBeanPostProcessors(beanFactory); // Initialize message source for this context. initMessageSource(); // Initialize event multicaster for this context. initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses.
          // 提供模板方法 给子类扩展, 默认是空 onRefresh(); // Check for listener beans and register them. registerListeners(); // Instantiate all remaining (non-lazy-init) singletons. finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. finishRefresh(); } catch (BeansException ex) { if (logger.isWarnEnabled()) { logger.warn("Exception encountered during context initialization - " + "cancelling refresh attempt: " + ex); } // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset ‘active‘ flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } finally { // Reset common introspection caches in Spring‘s core, since we // might not ever need metadata for singleton beans anymore... resetCommonCaches(); } } }

 

AbstractApplicationContext#refresh方法

原文:https://www.cnblogs.com/dayanjing/p/13999117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!