springboot学习随笔
程序员文章站
2022-04-19 19:08:06
...
//@SpringBootApplication
//标注这是一个springboot应用:启动类下的所以资源被导入
@SpringBootApplication
public class SpringbootApplication {
public static void main(String[] args) {
//将springboot应用启动
SpringApplication.run(SpringbootApplication.class, args);
}
}
注解:
@SpringBootConfiguration
@Configuration
@Component
@EnableAutoConfiguration //自动配置
@AutoConfigurationPackage //自动配置
@Import({Registrar.class}) //自动配置“包注册”
@Import({AutoConfigurationImportSelector.class})//自动配置导入选择
//获取候选的配置
List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);
获取候选配置源码
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());
Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.");
return configurations;
}
spring-boot-autoconfigure-2.2.6.RELEASE.jar
META-NINF/spirng.factories: 自动配置的核心文件
上一篇: springboot学习随笔