SpringBoot 自动配置实现流程

SpringBoot 自动配置实现流程1 SpringBoot 启动的时候加载主配置类 开启了自动配置功能 EnableAutoCo 查看 SpringBootAp 2 查看 EnableAutoCo 其作用是利用 AutoConfigur 给容器中导入一些组件 3 查看 AutoConfigur

(1)SpringBoot启动的时候加载主配置类,开启了自动配置功能@EnableAutoConfiguration。查看@SpringBootApplication

SpringBoot 自动配置实现流程

(2)查看@EnableAutoConfiguration,其作用是利用AutoConfigurationImportSelector给容器中导入一些组件。

SpringBoot 自动配置实现流程

(3)查看AutoConfigurationImportSelector,其中public String[] selectImports(AnnotationMetadata annotationMetadata)方法内

SpringBoot 自动配置实现流程

SpringBoot 自动配置实现流程

(4)查看 getCandidateConfigurations(AnnotationMetadata metadata,     AnnotationAttributes attributes),获取候选的配置,这个是扫描所有jar包类路径下”META-INF/spring.factories”;SpringBoot 自动配置实现流程

(5)然后把扫描到的这些文件包装成Properties对象。

(6)从properties中获取到EnableAutoConfiguration.class类名对应的值,然后把他们添加在容器中。

 

注:整个过程就是将类路径下”META-INF/spring.factories”里面配置的所有EnableAutoConfiguration的值加入到容器中。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/230128.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月16日 下午3:04
下一篇 2026年3月16日 下午3:04


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号