@SpringBootApplication
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) }) public @interface SpringBootApplication {
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @AutoConfigurationPackage @Import(AutoConfigurationImportSelector.class) public @interface EnableAutoConfiguration { String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration"; /** * Exclude specific auto-configuration classes such that they will never be applied. * @return the classes to exclude */ Class<?>[] exclude() default {}; /** * Exclude specific auto-configuration class names such that they will never be * applied. * @return the class names to exclude * @since 1.3.0 */ String[] excludeName() default {}; }
注意到AutoConfigurationImportSelector类
返回AutoConfigurationImportSelector.AutoConfigurationEntry基础上, AnnotationMetadata import的@Configuration类。
autoConfigurationMetadata - 自动配置的元数据
annotationMetadata - 配置类的注释元数据
返回:应导入自动配置
获得配置
返回应该被视为自动配置类名。 默认情况下,此方法将使用加载候选人SpringFactoriesLoader与getSpringFactoriesLoaderFactoryClass()
元数据 - 源元数据
属性-将annotation attributes
返回:候选配置列表
- 看下其中的断言中指定的
META-INF/spring.factories
为我们实现了很多自动装配
我们随便看下这个类
内嵌的 tomcat
其实就是开启 springMVC,这只是 sb 批量自动装配的一个组件
ServletWebServerFactoryAutoConfiguration
自动装配 - 启动一个内嵌的 tomcat