Spring Boot 教程(2) Spring Boot 启动类上注解 @SpringBootApplication 和spring-boot-starter-parent
Spring Boot 教程(2) Spring Boot 启动类上注解 @SpringBootApplication 和spring-boot-starter-parent
@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 {
}
由@EnableAutoConfiguration、@SpringBootConfiguration、@ComponentScan组合而成,默认扫描启动类所在包下的所有bean。如果要自定义扫描路径需要在启动类上使用@ComponentScan注解去指定特定的扫描路径。
spring-boot-starter-parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/>
</parent>
spring-boot-starter-parent为我们做了哪些功能呢?
1.定义了java 1.8
2.使用 UTF-8 格式编码
3.继承自 spring-boot-dependencies
,正是因为这个依赖,我们在写spring-boot-starter-*时不需要写版本号。
4.此外还定义了打包操作,自动化的资源过滤,自动化的插件配置,针对 application.properties 和 application.yml 的资源过滤,包括通过 profile 定义的不同环境的配置文件,例如 application-dev.properties 和 application-dev.yml。