【问题标题】:Maven Properties not referenced in properties file属性文件中未引用 Maven 属性
【发布时间】:2011-06-30 19:34:18
【问题描述】:

我的 maven pom.xml 中有一些属性。

<properties>
    <number>3</number>
    <age>38</age>
</properties>

(它们是随机属性)

在一个属性文件中,我们称之为resource.properties,我有以下内容:

value1 = ${number}
value2 = ${age}

当spring试图从这个文件中读取属性时,它无法从${number}得到引用,说找不到。

为什么会这样?我怎样才能让它发挥作用?或者根本不可能做到这一点。

编辑:我启用了过滤,但仍然无法正常工作。我的资源在src/test/resources 目录中。

这是我启用过滤的 pom 部分。

<build>
...
<resources>
      <resource>
          <directory>src/test/resources</directory>
          <filtering>true</filtering>
      </resource>       
  </resources>
...
</build>

【问题讨论】:

    标签: maven properties


    【解决方案1】:

    您需要告诉 maven 它使用哪些文件来替换占位符,例如

      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    

    maven filter

    【讨论】:

    • 它似乎对我不起作用。我是否将您发布的内容放在 中?还是别的地方?
    • 没关系,我不得不使用 testresources 而不是资源,谢谢
    【解决方案2】:

    您应该为 maven 资源插件启用资源过滤,如下所示:

      ...
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      ...
    

    详情请参阅Maven Resources Plugin section about filtering

    【讨论】:

    • 它似乎对我不起作用。我是否将您发布的内容放在 中?还是别的地方?
    • 是的,,你可能需要发出 mvn clean test
    猜你喜欢
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 2013-02-11
    • 2013-09-05
    • 1970-01-01
    • 2012-10-21
    • 2013-05-07
    相关资源
    最近更新 更多