依赖管理&&自动配置
依赖管理
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.3.4.RELEASE</version>
</parent>
- 父项目
- 包含众多jar包的版本号
- 在引入jar包时可以不需要版本号(自动版本仲裁机制)
- 也可自定义版本号(就近原则)
场景启动器
- spring-boot-starter-*
- *就某种场景
- 引入starter,本场景常规依赖依自动引入
- 所有场景
- https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter
- 第三方场景启动器
- *-spring-boot-starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>
自动配置
- tomcat
- tomcat依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>
- springmvc
- 默认包扫描规则
- 主程序所在包及其子包会被默认扫描
- 也可手动扫描
- @SpringBootApplication(scanBasePackages=“xx.xx”)
- @ComponentScan(“xx.xx”)
- 其他默认配置
- 配置文件的值会绑定每个类,在容器中创建对象
- 按需加载
- 自动配置类
- spring-boot-autoconfigure
@SpringBootApplication
等同于
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("xx.xx")