Springboot中的依赖管理

1.1依赖管理

在pom.xml中

<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>

ctrl+鼠标左键点击 <artifactId>spring-boot-starter-parent</artifactId>即可进入

在父项目spring-boot-dependencies中几乎声明了所有开发中常用的依赖的版本号

-----------------------------------------------------------------------------------------------------------------------

如何添加依赖:

比如添加使用mysql的依赖,在父项目spring-boot-dependencies-2.3.4.RELEASE.pom中搜索到mysql的依赖后,在pom.xml中添加即可。

1.查看spring-boot-dependencies中是否有对应依赖,

2.添加至pom.xml文件中:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

--------------------------------------------------------------------------------------------------------------------------
如何修改依赖的版本号:
1.查看spring-boot-denpendencies中规定当前依赖的版本使用的key

2.在项目的pom.xml中重写配置
如:mysql的版本号

<properties>
<mysql.version>5.1.43</mysql.version>
</properties>

--------------------------------------------------------------------------------------------------------------------------

开发导入starter场景启动器
1.在springboot项目的pom.xml文件中可以引入starter

spring-boot-starter-*


2.只要引入starter,这个场景的所有常规需要的依赖都会被自动引入,如:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

引入web场景
3.SpringBoot所有支持的场景见SpringBoot开发文档

https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems.starters
4.也可以使用第三方提供的简化开发的场景启动器
   *-spring-boot-starter

posted on 2022-06-30 16:09  风中明月  阅读(656)  评论(0)    收藏  举报