设为首页 加入收藏

TOP

SpringBoot自动装配深入理解(三)
2018-06-04 08:51:23 】 浏览:1422
Tags:SpringBoot 自动 装配 深入 理解
nbsp;         throw new BeanDefinitionStoreException(
                        "Failed to process import candidates for configuration class [" +
                        configClass.getMetadata().getClassName() + "]", ex);
            }
        }
    }


请大家关注这句代码:String[] imports = deferredImport.getImportSelector().selectImports(configClass.getMetadata());在这里deferredImport的类型为DeferredImportSelectorHolder:


private static class DeferredImportSelectorHolder {


        private final ConfigurationClass configurationClass;


        private final DeferredImportSelector importSelector;


        public DeferredImportSelectorHolder(ConfigurationClass configClass, DeferredImportSelector selector) {
            this.configurationClass = configClass;
            this.importSelector = selector;
        }


        public ConfigurationClass getConfigurationClass() {
            return this.configurationClass;
        }


        public DeferredImportSelector getImportSelector() {
            return this.importSelector;
        }
    }


在这个内部类里持有了一个DeferredImportSelector的引用,至此将会执行自动装配的所有操作


三、总结


  1)自动装配还是利用了SpringFactoriesLoader来加载META-INF/spring.factoires文件里所有配置的EnableAutoConfgruation,它会经过exclude和filter等操作,最终确定要装配的类


  2)  处理@Configuration的核心还是ConfigurationClassPostProcessor,这个类实现了BeanFactoryPostProcessor, 因此当AbstractApplicationContext执行refresh方法里的invokeBeanFactoryPostProcessors(beanFactory)方法时会执行自动装配。


首页 上一页 1 2 3 4 5 6 7 下一页 尾页 3/17/17
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇SpringBoot自动装配初步认识 下一篇智能指针之 shared_ptr

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目