配置的是一些基本属性
一、代码路径
1、SpringBootApplication注解
public @interface SpringBootApplication {
@AliasFor(
annotation = EnableAutoConfiguration.class
)
}
2、EnableAutoConfiguration注解
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration {
String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
Class<?>[] exclude() default {};
String[] excludeName() default {};
}
3、AutoConfigurationImportSelector类
getCandidateConfigurations调用 SpringFactoriesLoader类的loadFactoryNames方法。
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;
}
4、SpringFactoriesLoader类
getResources(“META-INF/spring.factories”)获取配置信息。
private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) {
MultiValueMap<String, String> result = (MultiValueMap)cache.get(classLoader);
if (result != null) {
return result;
} else {
try {
Enumeration<URL> urls = classLoader != null ? classLoader.getResources("META-INF/spring.factories") : ClassLoader.getSystemResources("META-INF/spring.factories");
LinkedMultiValueMap result = new LinkedMultiValueMap();

二、Spring.factories的几个常用自动配置
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
三、总结
spring-boot-autoconfigure包中:
xxxAutoConfiguration类用来自动加载配置、xxxProperties类是定义具体配置属性
在application.properties中设置debug=true,可以打印配置信息。
debug=true
server.port=8000
## sqlite 数据库
spring.datasource.driver-class-name=org.sqlite.JDBC
#数据库地址
spring.datasource.url=jdbc:sqlite:app.db
#每次启动更改数据表结构
spring.jpa.hibernate.ddl-auto=update
#显示数据库操作记录
spring.jpa.show-sql=true
四、扩展配置
五、参考
1、SpringBoot自动配置源码分析
2、狂神-MVC自动配置原理
3、官方:https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-auto-configuration