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需要進行替換

有些不需要替換的靜態模板文件(二進制文件),不需要加入。 加入的話, 會產生亂碼

方法二:二 + 三  結合使用

個人推薦 二 + 三  結合使用

 
        


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM