我在前面的Helloworld的程序中已经分析过一次,配置原理了:
2)、@EnableAutoConfiguration 作用:将 类路径下 META-INF/spring.factories 里面配置的所有
EnableAutoConfiguration的值加入到了容器中;
-
利用EnableAutoConfigurationImportSelector给容器中导入一些组件
-
可以查看selectImports()方法的内容;
- List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);获取候选的配置 SpringFactoriesLoader.loadFactoryNames()
扫描所有jar包类路径下 META-INF/spring.factories
把扫描到的这些文件的内容包装成properties对象
从properties中获取到EnableAutoConfiguration.class类(类名)对应的值,然后把他们添加在容器中