0
点赞
收藏
分享

微信扫一扫

SpringBoot 自动配置


1. 依赖管理

  • 父项目做依赖管理

依赖管理    
<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>

几乎声明了所有开发中常用的依赖的版本号,自动版本仲裁机制

  • 开发导入starter场景启动器

1、见到很多 spring-boot-starter-* : *就某种场景
2、只要引入starter,这个场景的所有常规需要的依赖我们都自动引入
3、SpringBoot所有支持的场景
https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter
4、见到的 *-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。
5、所有场景启动器最底层的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>

  • 无需关注版本号,自动版本仲裁

1、引入依赖默认都可以不写版本
2、引入非版本仲裁的jar,要写版本号。

2. 自动配置

  • 自动配好Tomcat
  • 自动配好SpringMVC
  • 自动配好Web常见功能,如:字符编码问题
  • 默认的包结构(主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来;无需以前的包扫描配置;想要改变扫描路径,@SpringBootApplication(scanBasePackages="com.atguigu") 或者@ComponentScan 指定扫描路径)

@SpringBootApplication
等同于
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.atguigu.boot")

  • 各种配置拥有默认值
  • 按需加载所有自动配置项 (非常多的starter; 引入了哪些场景这个场景的自动配置才会开启; SpringBoot所有的自动配置功能都在 spring-boot-autoconfigure 包里面)
举报

相关推荐

0 条评论