1.@SpringBootApplication 注解是Springboot的核心注解, 也是一个组合注解
@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 {
省略 .....
}
2.@SpringBootConfiguration
配置注解, 也是一个组合注解, Springboot项目中推荐使用@SpringBootConfiguration代替@Configuration
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
}
3.@EnableAutoConfiguration
启动自动配置,该注解会使Springboot根据项目中依赖的jar包自动配置项目的配置项
例如:我们添加了spring-boot-starter-web的依赖, 项目中也就会引入SpringMVC的依赖,Springboot就会自动配置tomcat和SpringMVC
4.@ComponentScan
默认扫描@SpringBootApplication所在类的同级目录及它的子目录