Maven - 引用子文件夹中的属性文件不起作用

时间:2014-04-15 22:45:26

标签: java spring maven maven-3

在我的Maven项目中,我有一个spring配置文件。它指的是一组属性文件。属性文件位于src / main / resources中的config文件夹下。 Spring配置文件在src / main / resources / META-INF / spring /下可用。在安装过程中,根据Maven标准,所有这些文件都在目标/类下可用。

现在在spring config XML中:如果我将属性文件引用到下面它不起作用

  

属性名称="位置"值="类路径:test.properties"                          或
      财产名称="地点"值="类路径*:test.properties"

我被迫提供子文件夹来实际引用必要的属性文件。这样的事情。

  

属性名称="位置"值="类路径: 配置 /test.properties"

这是Maven希望我们寻找属性文件的方式吗?请澄清并告诉我这是最好的方法。

谢谢

2 个答案:

答案 0 :(得分:1)

在Spring classpath引用classes文件夹。如果您的配置文件位于classesconfig的子文件夹下,则需要指定子文件夹名称。因此,这就是以下工作的原因:

  

property name =“location”value =“classpath:config / test.properties”

答案 1 :(得分:0)

它现在正在工作!我必须明确提到子文件夹作为新的资源文件夹。默认情况下,maven classpath将指向src / main / resources。如果我们想在特定子文件夹中包含属性文件和XML文件,则应在pom.xml中将其明确提及为单独的“build”标记,如下所示。

    <resource>
        <directory>src/main/resources/config</directory>
        <includes>
          <include>*.xml</include>
          <include>*.properties</include>
        </includes>            
    </resource>
相关问题