maven filter 作用

参考文档:https://www.cnblogs.com/1si2/p/maven_filter.html

参考文档(springboot 下载静态文件): https://blog.csdn.net/fuyingying_/article/details/107691999

maven 的 properties 加载顺序

`  一. <build><filters> 中的配置

   例如下面的示例: 

  1. 1. application-${profiles.active}.properties,application.properties 在代码中需要进行代码替换需要<filtering>true</filtering>
    2. **/*.xlsx 等是静态的模板文件,不需要进行变量替换, 所以<filtering>false</filtering>
    <build>
       <resources>
          <resource>
             <directory>src/main/resources</directory>
             <filtering>true</filtering>
             <includes>
                <include>application-${profiles.active}.properties</include>
             </includes>
          </resource>
    
          <resource>
             <directory>src/main/resources</directory>
             <filtering>false</filtering>
             <includes>
                <include>**/*.xls</include>
                <include>**/*.xlsx</include>
             </includes>
          </resource>
       </resources>
       <finalName>diablo-service</finalName>
    </build>

二 pom.xml 中 <profiles.active> 进行指定

<profiles> --  <profile> --  <properties> -- <profiles.active> 进行指定

<profiles>

		<profile>
			<id>local</id>
			<properties>
				<profiles.active>local</profiles.active>
			</properties>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
		</profile>

		<profile>
			<id>dev</id>
			<properties>
				<profiles.active>dev</profiles.active>
			</properties>
		</profile>
		<!--test environment-->
		<profile>
			<id>test</id>
			<properties>
				<profiles.active>test</profiles.active>
			</properties>
		</profile>
</profiles>

  

三 mvn -Dproperty=value 中定义的 property

相同 key 的 property,以最后一个文件中的配置为最终配置。

方法一: 一 + 三结合使用

作用: 主要是使用不同环境, application-${profiles.active}.properties 里面的变量profiles.active需要进行替换

有些不需要替换的静态模板文件(二进制文件),不需要加入。 加入的话, 会产生乱码

方法二:二 + 三  结合使用

个人推荐 二 + 三  结合使用


原文地址:https://www.cnblogs.com/daixianjun/p/maven-filter.html