@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