參考文檔:https://www.cnblogs.com/1si2/p/maven_filter.html
參考文檔(springboot 下載靜態文件): https://blog.csdn.net/fuyingying_/article/details/107691999
maven 的 properties 加載順序
` 一. <build><filters> 中的配置
例如下面的示例:
-
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需要進行替換
有些不需要替換的靜態模板文件(二進制文件),不需要加入。 加入的話, 會產生亂碼
方法二:二 + 三 結合使用
個人推薦 二 + 三 結合使用