因为AutoConfigurationImportSelector实现了ImportSelector接口,所以在底层配置时会调用AutoConfigurationImportSelector类的selectImports()方法;
public class AutoConfigurationImportSelector implements DeferredImportSelector, BeanClassLoaderAware,
ResourceLoaderAware, BeanFactoryAware, EnvironmentAware, Ordered {
.......
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
if (!isEnabled(annotationMetadata)) {
return NO_IMPORTS;
}
AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(annotationMetadata);
return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
}
.........
}
selectImports()方法返回的数组中是需要自动装配的全限定类名, 底层会根据数组中的全限定类名将这些类进行注入.
这些全限定名的获取的实现较为繁琐, 大致是获取类加载器并调用类加载器的getResources()方法得到该类路径下有"META-INF/spring.factories"文件的url, 然后就是一系列的算法对spring.factories读取进行获取, 最后返回这些自动配置类;