【springboot】2、 依赖管理

文章目录

  • 依赖管理
    • 基本介绍
    • 更改默认的版本
  • starter场景启动器
    • 官方提供的starter
    • 第三方starter

依赖管理

基本介绍

我们在pom.xml中引入了springboot父项目之后,再去引入某些依赖时,发现并不需要指定版本号
【springboot】2、 依赖管理_第1张图片
原因就是在spring-boot-starter-parent的父项目spring-boot-dependencies已经指定了版本很多jar的版本号
下面这个是spring-boot-starter-parent

在spring-boot-dependencies中指定了很多jar的版本号

如果我们在引入依赖时没有指定版本号,那么就默认使用父项目中的版本号

更改默认的版本

更改引入jar的默认版本有2种方式,一种是直接在种进行指定
我们先引入mysql,不进行指定版本


发现mysql的版本是8.0.26,下面我们通过来进行版本指定

发现已经成功覆盖了默认值,另外一种指定版本的方式是仿造spring-boot-dependencies中的写法,通过<\mysql.version>来指定,覆盖默认值
【springboot】2、 依赖管理_第2张图片
我们在pom.xml中的中进行指定

这样也能够成功覆盖

starter场景启动器

我们可以发现,在springboot中很多时候都是引入的starter

【springboot】2、 依赖管理_第3张图片
我们看一下spring-boot-starter-web引入了什么,可以发现引入了好几个starter,starter又引入了其它好多jar

【springboot】2、 依赖管理_第4张图片
【springboot】2、 依赖管理_第5张图片
可以发现我们引入了相关场景的 starter,这个场景中所有的相关依赖都引入进来了,比如我们将 web 开发引入了,该 starter 将导入与 web 开发相关的所有jar,这样就省去了导包的繁琐操作,提高了开发效率

官方提供的starter

查看的地址为https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems.starters
【springboot】2、 依赖管理_第6张图片
根据自己的需要引入即可

第三方starter

sprinboot也支持第三方starter,官方starter一般以spring-boot开头,而第三方starter一般以叫做
xxx-spring-boot-starter,例如mybatis与springboot的整合就叫做mybatis-spring-boot-starter
【springboot】2、 依赖管理_第7张图片

你可能感兴趣的:(springboot,spring,boot,java,spring)