Usage of '${spring.version}'

2020-08-09 06:13发布

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

4条回答
Rolldiameter
2楼-- · 2020-08-09 06:20

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>
查看更多
Deceive 欺骗
3楼-- · 2020-08-09 06:34

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.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-08-09 06:37

${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>
查看更多
疯言疯语
5楼-- · 2020-08-09 06:38
<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.

查看更多
登录 后发表回答