【问题标题】:Missing artifact org.springframework:spring-context:jar:${org.springframework-version}缺少工件 org.springframework:spring-context:jar:${org.springframework-version}
【发布时间】:2016-08-12 06:58:28
【问题描述】:

请问为什么我的 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>

【问题讨论】:

  • 您需要确保在定义org.springframework-version&lt;properties&gt; 块内有一个Maven 属性。喜欢&lt;properties&gt;&lt;org.springframework-version&gt;4.0.0.RELEASE&lt;/org.springframework-version&gt;&lt;/properties&gt;
  • 那么你需要它来添加它:)。
  • 我在其中一个节点中出现此错误 >>>> 缺少工件 org.hibernate:hibernate-core:jar:${hibernate.version}
  • 那么你现在需要添加属性hibernate.version,就像上面一样;)。
  • 我正在尝试这样做,但出现错误 >>>> 4.0.1

标签: java spring hibernate maven spring-mvc


【解决方案1】:

您所看到的${...} 称为Maven property

Maven 属性是值占位符,就像 Ant 中的属性一样。它们的值可以通过使用 ${X} 表示法在 POM 中的任何位置访问,其中 X 是属性。

在这种情况下,Maven 正在尝试访问属性 org.springframework-version,但它没有被定义,所以没有任何东西被替换。

您可以在 POM 中的 &lt;properties&gt; 部分的帮助下定义您的 own 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>

【讨论】:

  • 太棒了!非常感谢!
【解决方案2】:

很可能您没有将 spring 版本号添加到您的 pom 属性中。将此添加到您的 pom 中。

<properties>
    <org.springframework-version>4.2.5.RELEASE</org.springframework-version>
</properties>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-14
    • 2017-01-03
    • 2016-07-04
    • 2022-06-30
    • 2014-04-15
    • 2012-01-12
    • 2012-02-18
    • 2014-01-04
    相关资源
    最近更新 更多