spring-boot 的自动配置的原理

Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,
将该配置文件中的配置载入到Spring容器。

在这里插入图片描述

1. Maven下载源码

通过 dependency:sources 该命令可以下载该项目中所有的依赖的包的源码。

2.源码分析

org.springframework.boot.SpringApplication:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

这里的枚举就是
在这里插入图片描述

由此可见,读取该配置文件来加载内容。

3.举例:Redis的自动配置

从上述的配置中可以看出,
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
是Redis的自动配置。

在这里插入图片描述

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u014636209/article/details/86365622