0
点赞
收藏
分享

微信扫一扫

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性


学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性

学习springboot 的依赖管理机制。

分析pom文件里面的

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_mysql


父项目是用来做依赖管理的。

只有父项目写了版本:2.3.4.RELEASE

后面的dependency里面都没有写版本号。点击父项目:

按住ctrl键点击:

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_版本号_02


进入:

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_mysql_03


发现这里面还有一个父项目:

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_mysql_04

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

同理,按住ctrl键在进入:spring-boot-dependencies

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_springboot2_05


学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_mysql_06


进入它的properties标签:

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_mysql_07


学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_版本号_08

所以:

父项目的核心功能:就是声明了几乎所有开发中常用的依赖版本号。

这个就是springboot的自动版本的仲裁机制。

但是:

如果你想要自己定义版本号。不使用springboot提供的版本。

怎么做呢?

就拿mysql的驱动包来说:

首先在这个父项目:spring-boot-dependencies搜索mysql的版本。

搜索关键字:mysql.version

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_springboot2_09


发现它默认是8021版本。

目前在还没有修改之前:我们在自己项目里面写mysql的依赖,不写版本号。

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_spring_10

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

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_mysql_11


发现它自动就引入了8021版本。

现在我们不想使用默认的版本,向使用5143版本。

操作:

1、在pom文件的properties加上版本号

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_版本号_12


2、写依赖的时候,自己写上自己定义好的版本号:

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_springboot2_13


学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_版本号_14


这样依赖就编程我们自己定义的了。

Starters:场景启动器

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

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_mysql_15


学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_spring_16

现在在项目里面我们只导入了一个依赖:

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

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_spring_17


这个是:spring-boot-starter-web

未来会见到很多spring-boot-starter-*

这里我们只是用到了-web其实除了-web还有很多:

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_spring_18


所有这些spring-boot-starter-*,他们的基础都是:

spring-boot-starter,这个是核心。也是最基础的。

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_版本号_19

看我们自己项目里面的spring-boot-starter-web这个依赖的依赖树:

学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_springboot2_20


学习springboot2的第3天(2021-12-02)06-基础入门-springboot的依赖管理特性_spring_21


每一个场景启动器最基本的依赖都是:spring-boot-starter

这个是最底层的依赖。


举报

相关推荐

0 条评论