@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 { @AliasFor( annotation = EnableAutoConfiguration.class ) Class<?>[] exclude() default {}; @AliasFor( annotation = EnableAutoConfiguration.class ) String[] excludeName() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackages" ) String[] scanBasePackages() default {}; @AliasFor( annotation = ComponentScan.class, attribute = "basePackageClasses" ) Class<?>[] scanBasePackageClasses() default {}; }
前四个注解是元注解,用来修饰当前注解,后三个注解是真正起作用的注解
<beans>
,作用为:配置spring容器(应用上下文)会自动扫描指定包下全部标有@Component的类,并注册成bean,当然包括@Component下的子注解:@Service,@Repository,@Controller;默认会扫描当前包和所有子包。
根据类路径中jar包是否存在来决定是否开启某一个功能的自动配置。
原文:https://www.cnblogs.com/mufeng07/p/12125757.html