自动配置是什么?
SpringBoot框架是开发中的一大利器,其简化了spring的xml的配置,遵循了”约定大于配置“的原则,使用注解对常用的配置做默认配置,减少使用xml配置模式。SpringBoot为常用框架封装了大量的starter,比如spring-boot-starter-web会整合springmvc和内嵌的tomcat。SpringBoot在底层封装了默认的配置,修改配置在application.yml全局配置文件。如今在pom.xml文件中引用starter就可以使用这个框架,使用application.properties或者application.yml进行项目的全局配置。
主启动类:
SpringBootApplication:
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
}
@ComponentScan
这个注解在Spring中很重要 ,它对应XML配置中的元素。
作用:自动扫描并加载符合条件的组件或者bean , 将这个bean定义加载到IOC容器中
2、@SpringBootConfiguration
作用:Sprin