缺失的构件:org.springframework:spring-context:jar:${org.springframework-version}

5

请问为什么我的pom.xml文件会出现这个错误?

Missing artifact org.springframework:spring-context:jar:${org.springframework-version}

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>

3
你需要确保在 <properties> 块内定义了一个 Maven 属性,该属性定义了 org.springframework-version。例如 <properties><org.springframework-version>4.0.0.RELEASE</org.springframework-version></properties> - Tunaki
那么你需要将它添加进去 :)。 - Tunaki
我在其中一个节点上遇到了这个错误 >>>> 缺少依赖项 org.hibernate:hibernate-core:jar:${hibernate.version} - Blaze
然后,您现在需要添加属性hibernate.version,就像上面一样 ;)。 - Tunaki
我正在尝试做这件事,但是出现了错误 >>>> <properties> <hibernate.version> 4.0.1 </hibernate.version> </properties> - Blaze
2个回答

10
您所看到的 ${...} 是称为 Maven 属性 的值占位符:

Maven 属性是值占位符,类似于 Ant 中的属性。您可以使用记法 ${X}(其中 X 是该属性)在 POM 的任何位置访问它们的值。

在这种情况下,Maven 正试图访问属性 org.springframework-version,但未定义该属性,因此不会替换任何内容。
您可以借助 POM 中的 <properties> 部分来定义自己的Maven 属性
<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>

太棒了!非常感谢! - abhiagNitk

3
很可能您还没有将Spring的版本号添加到pom属性中,请在您的pom文件中添加该属性。
<properties>
    <org.springframework-version>4.2.5.RELEASE</org.springframework-version>
</properties>

将版本更改为您的项目所选的任何版本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接