SpringBoot依赖管理详解

一,SpringBoot导入dependency不需要指定版本

在开发过程中,SpringBoot项目会导入一个父类的dependency,这个依赖是需要去指定一个统一版本的,而这个版本根据实际开发而变更

 <parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent<11./artifactId>
     <version>2.2.2.RELEASE</version>
     <relativePath/> <!-- lookup parent from repository -->
 </parent>

从这用鼠标左键+ctrl点入,发现在parent的底层还有一个依赖:Spring-boot-dependencies

<parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-dependencies</artifactId>
     <version>2.2.2.RELEASE</version>
     <relativePath>../../spring-boot-dependencies</relativePath>
</parent>

同样的方法继续点入进去,发现会对一些常用的依赖文件进行了版本号的限定,比如mysql,activemq,solr,tomcat.....。而这些则与最上层的SpringBoot2.2的版本像绑定,减少了在搭建环境时因为依赖版本冲突不匹配等问题导致运行失败。

<properties>
     <activemq.version>5.15.11</activemq.version>
     ...
     <solr.version>8.2.0</solr.version>
     <mysql.version>8.0.18</mysql.version>
     <kafka.version>2.3.1</kafka.version>
     <spring-amqp.version>2.2.2.RELEASE</spring-amqp.version>
     <spring-restdocs.version>2.0.4.RELEASE</spring-restdocs.version>
     <spring-retry.version>1.2.4.RELEASE</spring-retry.version>
     <spring-security.version>5.2.1.RELEASE</spring-security.version>
     <spring-session-bom.version>Corn-RELEASE</spring-session-bom.version>
     <spring-ws.version>3.0.8.RELEASE</spring-ws.version>
     <sqlite-jdbc.version>3.28.0</sqlite-jdbc.version>
     <sun-mail.version>${jakarta-mail.version}</sun-mail.version>
     <tomcat.version>9.0.29</tomcat.version>
     <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
     <thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-dataattribute.version>
     ...
 </properties>

二,SpringBoot启动项目运行的jar包依赖

这了简单举个例子,在SpringBoot用到了Spring表现层的Controller,那么势必引用了SpringMVC相关的依赖,那么这是在哪儿引用进来的?使用MVC,SpringBoot需要去引入spring-boot-starter-web依赖,这个依赖点进去。

以下为spring-boot-starter-webׁ引入依赖部分

<dependencies>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
         <version>2.2.2.RELEASE</version>
         <scope>compile</scope>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-json</artifactId>
         <version>2.2.2.RELEASE</version>
         <scope>compile</scope>
         </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-tomcat</artifactId>
         <version>2.2.2.RELEASE</version>
         <scope>compile</scope>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-validation</artifactId>
         <version>2.2.2.RELEASE</version>
         <scope>compile</scope>
         <exclusions>
             <exclusion>
                 <artifactId>tomcat-embed-el</artifactId>
                 <groupId>org.apache.tomcat.embed</groupId>
             </exclusion>
         </exclusions>
     </dependency>
     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-web</artifactId>
         <version>5.2.2.RELEASE</version>
         <scope>compile</scope>
     </dependency>
     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-webmvc</artifactId>
         <version>5.2.2.RELEASE</version>
         <scope>compile</scope>
     </dependency>
</dependencies>

而且不仅仅是web-started,SpringBoot的官方文档中同样提供了其它场景下开发的启动器

猜你喜欢

转载自blog.csdn.net/qq_42773863/article/details/120497449