为什么springboot依赖不写版本号?

xml 复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

有时候我们看到SpringBoot项目的依赖不写版本号,为什么这样呢?这样可以吗?为什么不报错?

也就是说为什么在有的spring项目中的maven配置中,写依赖<dependencies>时,有的不用写版本号<version>

为什么在有的spring项目中的maven配置中,写依赖时,有的不用写版本号

一、第一种情况:

java 复制代码
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

如同以上

一般出现这种情况,是因为。

  1. 继承了spring-boot的配置,这里引入spring-boot-starter-parent的好处是在添加启动器时不用申明版本号!
java 复制代码
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

因为添加了标签

spring-boot-starter-parenth会为我们提供常用jar包版本,其实不是不用指定,是人家为我们指定好了。

自己指定版本号也可以,会覆盖官方版本,这时可以用maven helper查看一下有没有冲突即可。

相关推荐
用户7713970207061 小时前
我在项目里发现了一个“神秘文件“——.editorconfig
后端
盏灯1 小时前
mac 外接磁盘,热更新失效
前端·后端
ihuyigui2 小时前
海外签收通知短信接口
android·java·开发语言·前端·数据库·后端
腾渊信息科技公司2 小时前
Spring Boot + TDengine:工业视觉检测数据实时同步方案实战
spring boot·后端·tdengine
用户40966601317512 小时前
MyBatis、MyBatis-Plus、通用 Mapper:一张图说清三者的血缘关系
后端
爬楼的猪2 小时前
WSL 的 GUI 为什么总是卡卡的
后端
程序猿DD4 小时前
OPC必备!在 Cloudflare Worker 上免费部署 AI 网关:集中管理与供应 Token
后端
LucianaiB4 小时前
遇到 Seed Evolving,我终于把脑海里的小说世界图谱做出来了:《斗破苍穹》篇
后端
JuiceFS5 小时前
GPFS、Alluxio、JuiceFS 怎么选?一文看懂架构与适用场景
人工智能·后端
武子康5 小时前
1.2GB 离线语音 Agent 真正值得复用的不是 908ms:四阶段职责 + 状态感知 Tool Schema + 可观测时间锚点
人工智能·后端·agent