### 依赖管理 ● 父项目做依赖管理 我们在pom.xml中添加了父项目`spring-boot-starter-parent` ```bash <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> </parent> ``` `spring-boot-starter-parent`的父项目: ``` <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.3.4.RELEASE</version> </parent> ``` `spring-boot-dependencies`几乎声明了所有开发中常用的依赖的版本号,自动版本仲裁机制 ```bash <properties> <activemq.version>5.16.6</activemq.version> <antlr2.version>2.7.7</antlr2.version> <appengine-sdk.version>1.9.98</appengine-sdk.version> <artemis.version>2.19.1</artemis.version> <aspectj.version>1.9.7</aspectj.version> <assertj.version>3.22.0</assertj.version> <atomikos.version>4.0.6</atomikos.version> <awaitility.version>4.2.0</awaitility.version> <build-helper-maven-plugin.version>3.3.0</build-helper-maven-plugin.version> <byte-buddy.version>1.12.23</byte-buddy.version> <cache2k.version>2.6.1.Final</cache2k.version> <caffeine.version>2.9.3</caffeine.version> <cassandra-driver.version>4.14.1</cassandra-driver.version> <classmate.version>1.5.1</classmate.version> <commons-codec.version>1.15</commons-codec.version> <commons-dbcp2.version>2.9.0</commons-dbcp2.version> ...省略其余代码 ``` > 在我们项目开发中,父项目把我们开发中使用的常用jar包的依赖都管理起来,并且指定对应jar包的版本号,因此,我们在pom.xml中可以不用指定version(版本号) **小结:** 无需关注版本号,自动版本仲裁 1、引入依赖如果在spring-boot-dependencies中定义了,可以不写版本号 2、引入非版本仲裁的jar,要写版本号 ### 修改默认版本号 示例mysql-connector修改版本号: 1、查看`spring-boot-dependencies`里面规定当前依赖的版本 用的 key,如: `<mysql.version>8.0.33</mysql.version>` 2、查找想要替换的版本: mvn仓库: [https://mvnrepository.com/](https://mvnrepository.com/) 如,我们要替换的版本为6.0.5 ![](https://img.kancloud.cn/a8/0f/a80fdfb6aff7b9453cbe0e55f5da17e5_837x267.png =1000x) 3、在当前项目的pom.xml文件中可以重写配置 ```bash <properties> <mysql.version>6.0.5</mysql.version> </properties> ``` ### 场景启动器(starter) 开发导入starter场景启动器: 1、见到很多 spring-boot-starter-\* : \*表示某种场景,如web. 2、只要引入starter,这个场景的所有常规需要的依赖我们都自动引入 3、SpringBoot所有支持的场景 [https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter](https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter) 4、见到的 \*-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。 5、所有场景启动器最底层的依赖`spring-boot-starter` ```bash <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.7.13</version> </dependency> ``` ### 图形化展示依赖 可以通过idea提供的功能,在pom.xml文件中某个依赖右键,查看该starter的依赖图形关系,如:spring-boot-starter-web ![](https://img.kancloud.cn/12/1f/121ffccc9a5ce4052f048c98f992d019_1295x812.png =1000x) 可以通过生成的依赖关系图查看到spring-boot-starter-web所依赖的其它包。 ![](https://img.kancloud.cn/d0/8b/d08b04015ce2f1489ea53dfc6b5d4034_1287x1060.png =1000x)