resources资源过滤

        <filters>
            <filter>../src/filters/${env.name}/datasource.properties</filter>
            <filter>../src/filters/${env.name}/config.properties</filter>
            <filter>../src/filters/${env.name}/dubbo.properties</filter>
        </filters>
        <resources>
            <!-- 保证所有的resources下的配置文件能被编译打包,即能够被复制到classpath目录下 -->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <!-- 保证resources下的所有的配置文件可以被过滤,即可以根据profile进行属性替换 -->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                   <include>**/*.yml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

maven的pom文件中的build构建标签下我们通常需要指定环境、资源文件和maven插件,这边没搞明白resource下的这个filetering到底是什么意思,下面先看一下maven的xsd中对于这个标签的说明:

<xs:element name="filtering" minOccurs="0" type="xs:boolean" default="false">
        <xs:annotation>
          <xs:documentation source="version">3.0.0+</xs:documentation>
          <xs:documentation source="description">
            Whether resources are filtered to replace tokens with parameterised values or not.
            The values are taken from the &lt;code&gt;properties&lt;/code&gt; element and from the properties in the files listed
            in the &lt;code&gt;filters&lt;/code&gt; element.
          </xs:documentation>
        </xs:annotation>
      </xs:element>

翻译过来即表示:filetering是一个boolean变量,标明是否需要根据上面配置的各种filter环境所指定的配置文件对这些资源文件里面的占位符进行替换。

所以最上面的配置表示:对src/main/resources下的所有文件都不进行过滤占位符替换,对src/main/resources下的所有yml文件进行过滤占位符替换。

但我测试了一下如果对src/main/resources下的所有文件都进行无差别过滤的话,项目功能没什么问题,但对于web项目中的界面用到的fontawesome图标会出现读取不到的情况,可能还会有其他影响,所以还是老老实实用上面的写法吧。

猜你喜欢

转载自blog.csdn.net/weixin_33919941/article/details/86828990