-->

Usage of '${spring.version}'

2020-08-09 05:46发布

问题:

When I use:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
</dependency>

on the console i get the following error message:

'dependencies.dependency.version' for org.springframework:spring-context:jar must be a valid version but is '${spring.version}'. @ line 40, column 19

Do I have to do a manually configuration of Maven? i'v seen this kind of dependciy but there is no explanation how to do it properly..thx in advance

回答1:

${spring.version} is a placeholder, you need to configure its actual value in <properties> block:

<properties>
    <spring.version>3.0.5.RELEASE</spring.version>
</properties>


回答2:

I don't really agree with the first answer.

Using ${spring.version} is a convenient way to config version.

In xml file, you need to set property like follow:

<properties>
    <spring.version>4.3.3.RELEASE</spring.version>
</properties>

Then it will work.



回答3:

<properties>
    <spring.version>4.3.2.RELEASE</spring.version>
    <junit.version>4.12</junit.version>
</properties>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
</dependency>

if you want to use ${spring.version} then first define its version in properties tag and it is good practice to use to define the version in properties tag because if we change the version then we don't need to do changes in the entire file just do change in properties tag.



回答4:

There is a simple answer for that.
Add spring.version to properties section in pom.xml.

<properties>
    <spring.version>4.0.2.RELEASE</spring.version>
</properties>