SpringBootApplication
从上面的图片可以清楚的看到SpringBootApplication包含@EnableAutoConfiguration注解和@SringBootConfiguration 注解。
@EnableAutoConfiguration的作用
![这是EnableAutoConfiguration注解类即它的一些注解]](https://img-blog.csdnimg.cn/20191108100805274.png)
从classpath中搜索所有的META-INF/spring.factories配置文件,将其中EnableAutoConfiguration key对应的配置项加载到Spring容器。只有EnableAutoConfiguration 为true(默认为true)的时候,才会启动配置。还可以进行排除操作,排除的方式有两种:一种是根据class来排除(exclude),二是根据classname来排除(excludeName)。
@SringBootConfiguration 的作用
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
}
使用@Configuration 标注的类就是一个配置类, 它具有
xml 配置文件的所有功能, 用它来代替 xml 配置文件, 并且会把这个配置类纳入
到 Spring 容器中。
@ComponentScan的作用
扫描被注解标识的类,并将其装入Spring容器。减少了xml配置项,一般用xml灵活一些,可以省去重新编译发布的事。