Spring Boot 依赖管理特性

来自姬鸿昌的知识库
跳到导航 跳到搜索

https://www.bilibili.com/video/BV19K4y1L7MT/?p=6

父项目做依赖管理

boot-01-helloworld - pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>


spring-boot-starter-parent-2.3.4.RELEASE.pom

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.3.4.RELEASE</version>
  </parent>
  <artifactId>spring-boot-starter-parent</artifactId>
  <packaging>pom</packaging>
  <name>spring-boot-starter-parent</name>


spring-boot-dependencies-2.3.4.RELEASE.pom

  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-dependencies</artifactId>
  <version>2.3.4.RELEASE</version>
  <packaging>pom</packaging>
  <properties>
    <activemq.version>5.15.13</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine-sdk.version>1.9.82</appengine-sdk.version>
    <artemis.version>2.12.0</artemis.version>
  ……
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-amqp</artifactId>
        <version>${activemq.version}</version>
      </dependency>
      ……
    </dependencies>
  </dependencyManagement>

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


如果对自动仲裁的版本不满意,还可以到当前项目的配置文件里进行自定义:

  1. 查看 spring-boot-dependencies 里面规定当前依赖的版本用的 key。
  2. 在当前项目里面重写
        <properties>
            <mysql.version>5.1.43</mysql.version>
        </properties>
    


各种各样的 starter (场景启动器)

https://docs.spring.io/spring-boot/docs/2.7.8/reference/html/using.html#using.build-systems.starters


所有的场景启动器最底层的依赖

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>2.3.4.RELEASE</version>
      <scope>compile</scope>
    </dependency>

所以一旦依赖了场景启动器,就不用才引入对 spring-boot-starter 的依赖了