1.SpringBoot自动配置是什么?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
在spring boot使用注解或一些配置实现某一种功能。
SpringBoot 定义了一套接口规范,这套规范规定:SpringBoot 在启动时会扫描外部引用 jar 包中的 META-INF/spring.factories 文件,将文件中配置的类型信息加载到 Spring 容器,并执行类中定义的各种操作。对于外部 jar 来说,只需要按照 SpringBoot 定义的标准,就能将自己的功能装置进 SpringBoot。
2.SpringBoot如何实现自动配置?
@SpringBootApplication注解位于启动类上,它的内部包含@EnableAutoConfiguration、@SpringBootConfiguration (这个注解包含配置注解@Configuration),
1.配置自动装配开关,默认 spring.boot.enableautoconfiguration = true,可不配置,也可在 application.properties 或 application.yml 中设置。
2.用于获取@EnableAutoConfiguration 注解中的 exclude 和 excludeName。
3.从 META-INF/spring.factories 读取需要自动装配的所有配置类。(@ConditionOnxxx 中的所有条件都满足,该类才会生效)
4.配置类中的bean对象创建及对应功能的使用,如,redis中对连接的封装,可以简单使用StringRedisTemplate
资料引用: