自动配置原理分析
2021-06-20 17:53:46 7 举报
AI智能生成
springboot启动图
作者其他创作
大纲/内容
@springbootApplication
@springbootconfiguration
@EnableAutoConfiguration:自动导入包
@AutoConfigurationPackage
@Import({Registrar.class}):自动注册包
@Import({AutoConfigurationImportSelector.class}):自动导入包的核心
AutoConfigurationImportSelector:自动选择器
getAutoConfigurationEntry:获取候选的配置
getCandidateConfigurations
protected Class<?> getSpringFactoriesLoaderFactoryClass() {
return EnableAutoConfiguration.class;
}======标注了EnableAutoConfiguration注解的类
return EnableAutoConfiguration.class;
}======标注了EnableAutoConfiguration注解的类
public static List<String> loadFactoryNames(Class<?> factoryType, @Nullable ClassLoader classLoader) {
ClassLoader classLoaderToUse = classLoader;
if (classLoader == null) {
classLoaderToUse = SpringFactoriesLoader.class.getClassLoader();
}
String factoryTypeName = factoryType.getName();
return (List)loadSpringFactories(classLoaderToUse).getOrDefault(factoryTypeName, Collections.emptyList());
}======获取所有的加载配置
ClassLoader classLoaderToUse = classLoader;
if (classLoader == null) {
classLoaderToUse = SpringFactoriesLoader.class.getClassLoader();
}
String factoryTypeName = factoryType.getName();
return (List)loadSpringFactories(classLoaderToUse).getOrDefault(factoryTypeName, Collections.emptyList());
}======获取所有的加载配置
Enumeration urls = classLoader.getResources("META-INF/spring.factories");====加载资源
spring.factories在spring-boot-autoconfigure-2.6.0-SNAPSHOT.下
从资源中遍历了所有的元素
所有的自动配置类都在spring-boot-autoconfigure-2.6.0-SNAPSHOT.jar 这个包下面
@ComponentScan:扫描当前主启动类同级的包
0 条评论
下一页