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>
如同以上
一般出现这种情况,是因为。
- 继承了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查看一下有没有冲突即可。