@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
SpringBootApplication
是一个组合注解,其中主要的注解@EnableAutoConfiguration
@EnableAutoConfiguration
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration
EnableAutoConfiguration
启用自动装配,也是一个组合注解。
@Import
注解导入AutoConfigurationImportSelector
类,这个类会扫描 spring.factories 中的配置文件,加载配置类,完成自动装配。
@AutoConfigurationPackage
自动扫描并导入Bean
@AutoConfigurationPackage
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({AutoConfigurationPackages.Registrar.class})
public @interface AutoConfigurationPackage
@AutoConfigurationPackage
自动扫描并导入Bean
@Import
注解导入AutoConfigurationPackages.Registrar
类,这个类会扫描前类的包及子包,用于导入并装配用户自定义类
欢迎小伙伴们积极指正和讨论,一起共同成长。