一、场景:
在Maven项目中,为了减少不必要的冲突,在导入jar依赖时,我们通常会使用统一的版本。
而为了减少编写时的失误,我们可以配置统一的版本号。
二、解决:
使用<properties></properties>标签进行配置
三、具体使用:
在<properties>标签中定义好版本号,再在具体的依赖中使用${}引用即可。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.xbao</groupId>
<artifactId>javaConfig</artifactId>
<version>1.0</version>
<properties>
<spring.version>5.0.8.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>