①. 整体查看主启动类
- ①. 主启动类如下
@SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } }
②. 重点分析
@SpringBootConfiguration @EnableAutoConfiguration @ComponentScan
@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} )} )
②. @SpringBootConfiguration
- ①. 在SpringBootConfiguration中有一个注解@Configuration,标注这个注解的类就是一个配置类
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration public @interface SpringBootConfiguration { @AliasFor( annotation = Configuration.class ) boolean proxyBeanMethods() default true; }
②. @Configuration这个注解用于以JavaConfig的方式来定义配置类,可替换 xml 配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被AnnotationConfigAppli cationContext或AnnotationConfig WebApplicationContext类进行扫描,并用于构建bean定义,初始化Spring容器。这也是SpringBoot中没有xml配置文件的原因,SpringBoot都是通过配置类的方式将Bean注入到SpringIOC的容器中