Skip to content
目录概览

SpringBoot的核心注解是什么?由那些注解组成?

启动类上@SpringBootApplication是 SpringBoot 的核心注解

java
@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 {
1
2
3
4
5
6
7
8
9
10

主要组合包含了以下 3 个注解:

  • @SpringBootConfiguration: 组合了 @Configuration 注解,实现配置文件的功能。

  • @EnableAutoConfiguration: 打开自动配置的功能,也可以关闭某个自动配置的选项,如关闭数据源自动配置功能: @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })。

  • @ComponentScan: Spring组件扫描。