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

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


一、第一种情况:


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

如同以上

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

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

**

二、第二种情况

**

 <dependencies>
        <!-- junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <!-- 该jar包保留到测试 -->
            <scope>test</scope>
        </dependency>
        <!-- jsp-api、servlet-api、el -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jsp-api</artifactId>
            <version>${jsp.api.version}</version>
            <!-- 该jar包最终由Web容器提供 -->
            <scope>provided</scope>
        </dependency>
    </dependencies>

那是因为在maven文件中的靠前位置中有属性文件

<properties>
        <junit.version>4.11</junit.version>
        <jsp.api.version>8.5.5</jsp.api.version>
    </properties>

补充:在做大项目的时候,一定要注意jar包之间的兼容问题。jar包引入过多,如果不兼容,总是会报错,这类错误也是最难查的。

  • 9
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值