1、springBoot和spring的关系
- springBoot是整合spring技术栈的的一站式服务(springMVC,springSecurit......)
- springBoot是简化spring技术栈的快速开发脚手架(不需要再写特别多的配置信息)
springBoot的特点
● Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
○ 内嵌web服务器
● Provide opinionated 'starter' dependencies to simplify your build configuration
○ 自动starter依赖,简化构建配置
● Automatically configure Spring and 3rd party libraries whenever possible
○ 自动配置Spring以及第三方功能
● Provide production-ready features such as metrics, health checks, and externalized configuration
○ 提供生产级别的监控、健康检查及外部化配置
● Absolutely no code generation and no requirement for XML configuration
○ 无代码生成、无需编写XML
2、springBoot特性详解
2.1 依赖管理
(1)依赖管理特性(父项目做依赖管理)
理解:指定一个spring-boot-starter-parent的版本后,项目中一些其他的常用的依赖,再导入时就不需要再指定版本,因为spring-boot-starter-parent引入的spring-boot-dependencies已经根据指定的版本号,把其他常用的依赖版本号指定好(自动匹配版本号)
(2)开发导入starter场景启动器
理解:场景-》产品,功能组件,功能插件,例如mysql,redis
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>
(3)修改默认的版本号
1、查看spring-boot-dependencies里面规定当前依赖的版本 用的 key。
2、在当前项目里面重写配置
<properties>
<mysql.version>5.1.43</mysql.version>
</properties>
2.2 自动配置
(1)组件自动配置
step1:引入依赖(上一章节)
step2:自动配置(见下面章节)
(2)自动配置都有默认值
默认配置最终都是映射到某个类上,这个类会在容器中被创建,如ServerProperties
(3)按需加载配自动配置项
引入了哪个场景,则加载哪个场景的配置项
例:如未引入mysql,则不会加载mysql的最长等待时间:max-wait