缺少工件org.springframework:spring-context:jar:$ {org.springframework-version}

Bla*_*aze 4 java spring hibernate spring-mvc maven

请问我为什么在我的pom.xml文件中收到此错误

Missing artifact org.springframework:spring-context:jar:${org.springframework-version}
Run Code Online (Sandbox Code Playgroud)

xml文件

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${org.springframework-version}</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
         </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

Tun*_*aki 9

您所看到的${...}被称为Maven属性:

Maven属性是值占位符,就像Ant中的属性一样.通过使用符号${X},可以在POM内的任何位置访问它们的值,X属性在哪里.

在这种情况下,Maven正在尝试访问该属性,org.springframework-version但它没有定义,因此没有任何内容被替换.

您可以在POM 中的部分的帮助下定义自己的Maven属性<properties>:

<properties>
    <org.springframework-version>4.2.5.RELEASE</org.springframework-version> <!-- wanted Spring version -->
    <hibernate.version>5.1.0.Final</hibernate.version> <!-- wanted Hibernate version -->
</properties>
Run Code Online (Sandbox Code Playgroud)