@SpringBootApplication是可以将一个类标注为springboot导入类。标注该类之后,没有web.xml文件,DispatcherServletAutoConfiguration没有配置,但是却可以直接访问controller,项目没有配置tomcat,却可以直接部署到tomcat。@SpringBootApplication如此强大,它是怎么做到这些的?
以下“–>”都代表进入查看源码
分析
@SpringBootApplication–>三个核心注解@SpringBootConfiguration, @EnableAutoConfiguration,@ComponentScan
@SpringBootConfiguration—>@Configuration:该注解标注类成为spring配置文件类,作用就是替代spring配置文件开发的spring的xml配置文件
@ComponentScan:扫描springboot导入类同级目录下的@bean组件
接下来进入大佬角色@EnableAutoConfiguration
@EnableAutoConfiguration–>@Import({AutoConfigurationImportSelector.class})---->AutoConfigurationImportSelector.class---->this.getCandidateConfigurations()---->
Assert.notEmpty(configurations, “No auto configuration classes found in META-INF/spring.factories. If you are using a custom pack