为什么在有的spring项目中的maven配置中,写依赖时,有的不用写版本号
一、第一种情况:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
如同以上
一般出现这种情况,是因为。
- 继承了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包引入过多,如果不兼容,总是会报错,这类错误也是最难查的。