急求大神帮忙,Spring Boot原理相关

之前学习了如何使用SpringBoot,但是未曾深入去了解它的各项配置原理等等。于是最近就开始了学习SpringBoot的配置等原理。在学习的过程当中,遇到如下的疑惑,希望有大神可以指导解决一下,非常感谢。

问题:

在SpringBoot框架的主程序类中的@SpringBootApplication,点击进入SpringBootApplication,再进入其中的@EnableAutoConfiguration注解,为什么我这里给Spring容器导入的组件是AutoConfigurationImportSelector而不是EnableAutoConfigurationImportSelector呢?我现在只知道EnableAutoConfigurationImportSelector是继承的AutoConfigurationImportSelector,并且他的作用是可以帮助SpringBoot应用将所有符合条件的@Configuration配置都加载到当前SpringBoot创建并使用的IoC容器。

https://img3.mukewang.com/5b8df8e100013d9006500194.jpg

https://img1.mukewang.com/5b8df8fd0001468205100268.jpg

https://img2.mukewang.com/5b8df91500017de306520260.jpg

求大神大神解答一下,希望可以一并讲解一下EnableAutoConfigurationImportSelector与AutoConfigurationImportSelector的异同,谢谢!





想成为攻城师的筱筱
浏览 1941回答 2
2回答

pardon110

程序运行时。一个导入自定义,一个导入默认的。合起来的意思就是,当你没有使用自定义的情况下,采用默认值 。

哈哈吧

先说结论:EnableAutoConfigurationImportSelector和AutoConfigurationImportSelector就功能上来说没什么差异,都是spring1.3带入的ImportSelector,而且EnableAutoConfigurationImportSelector本身也是继承AutoConfigurationImportSelector的,只是enable查看其是否为自定义导入的,而auto为自动导入的现在EnableAutoConfigurationImportSelector已经不被推荐使用了,在springboot1.x以及spring4.x都还是使用EnableAutoConfigurationImportSelector,而springboot2.x和spring5都采用了AutoConfigurationImportSelector如果看过cloud会发现很多@Enable系列,可能spring官方的意思更多的是希望利用start模式去方便扩充更多自定义的组件,故有很多三方的Enable,而自动导入则升级为核心包的一个默认功能吧
打开App,查看更多内容
随时随地看视频慕课网APP