@SpringBootApplication註解
一、@SpringBootApplication是一個組合註解,加在專案啟動類上。
二、@SpringBootApplication定義:
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
//略
}
可以看出@SpringBootApplication由三個註解組成。
- @SpringBootConfiguration ,本質是一個@Configuration配置類(類似一個SpringContext.xml檔案),可以通過@Bean定義方法定義Bean。
/**
* Indicates that a class provides Spring Boot application
* {@link Configuration @Configuration}. Can be used as an alternative to the Spring's
* standard {@code @Configuration} annotation so that configuration can be found
* automatically (for example in tests).
* <p>
* Application should only ever include <em>one</em> {@code @SpringBootConfiguration} and
* most idiomatic Spring Boot applications will inherit it from
* {@code @SpringBootApplication}.
*
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.4.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
//***
}
- @EnableAutoConfiguration 自動配置類
@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 {};
}
- @ComponentScan 元件掃描類. 類似SpringContext.xml檔案zhong的 <context:component-scan>
@Repeatable(ComponentScans.class)
public @interface ComponentScan {
//
}
相關文章
- 使用 @SpringBootApplication 註解Spring BootAPP
- springboot系列文章之SpringBootApplication註解Spring BootAPP
- 神秘又強大的@SpringBootApplication註解Spring BootAPP
- 精盡Spring Boot原始碼分析 - 剖析 @SpringBootApplication 註解Spring Boot原始碼APP
- SpringBoot 中 @SpringBootApplication註解背後的三體結構探祕Spring BootAPP
- 簡明易理解的@SpringBootApplication註解原始碼解析(包含面試提問)Spring BootAPP原始碼面試
- springboot自動裝配(1)---@SpringBootApplication註解怎麼自動裝配各種元件Spring BootAPP元件
- @SpringBootApplication和@SpringBootConfiguration的關係Spring BootAPP
- 註解專題(一)Java元註解,內建註解Java
- JAVA-註解(2)-自定義註解及反射註解Java反射
- Java註解-後設資料、註解分類、內建註解和自定義註解Java
- @ResponseBody註解和@RequestBody註解使用
- 【Spring註解】事務註解@TransactionalSpring
- 註解
- Java註解詳解「註解專案實戰」Java
- Java中的註解-自定義註解Java
- 【String註解驅動開發】你瞭解@PostConstruct註解和@PreDestroy註解嗎?Struct
- Java註解解析-搭建自己的註解處理器(CLASS註解使用篇)Java
- SwaggerAPI註解詳解,以及註解常用引數配置SwaggerAPI
- Spring 註解程式設計之模式註解Spring程式設計模式
- Spring註解Spring
- @Bean 註解Bean
- Annotation註解
- 註解 @component
- @import註解Import
- SpringBoot註解Spring Boot
- 註解 javaJava
- 常用註解
- java註解Java
- 註解類
- 註解 & 反射反射
- 註解和註釋區別
- Java註解詳解Java
- Lombok 註解詳解Lombok
- @FeignClient註解詳解client
- Java 註解詳解Java
- Java ”框架 = 註解 + 反射 + 設計模式“ 之 註解詳解Java框架反射設計模式
- 每日註解學習(九)@PostConstruct和@PreConstruct註解Struct