自动装配(约定大于配置)
-
主程序类的main方法在加载过程会调用refreshContext(context)刷新容器方法,该方法启用了注解@SpringBootApplication=@ComponentScan(扫描包) + @SpringBootConfiguration + @EnableAutoConfiguration;
-
@EnableAutoConfiguration里组合了@Import(AutoConfigurationImportSelector.class) 加载了AutoConfigurationImportSelector类,该类下有一个selectImports方法;
-
selectImports方法调用了AutoConfigurationMetadataLoader里的一个loadMetadata,该loadMetadata会去扫描路径为 META-INF/spring.factories ,从而加载properties资源
-
在springboot的autoconfiguration包下的spring.factories里根据全类名反射配置里各种jar对应需要加载的autoconfiguration类,在具体的类上会@ConditionalOnClass(xxx.class)或者@ConditionalOnMissingClass(xxx.class)根据是否导入了jar包而加载资源。