springboot可以從 pom 文件中獲取參數,這樣可以 在打包時,根據環境(開發、測試)指定參數,就不用再 運行jar 包再指定參數了。
最常用的就是,激活配置文件參數:spring.profiles.active=activeProperty
用法:
1)springboot 配置文件
#propertis文件方式
spring.profiles.active=@activatedProperties@
#yaml文件方式
spring:
profiles:
active: @activatedProperties@
2)pom文件
<profiles>
<profile>
<!-- 開發 -->
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
</profile>
<profile>
<!-- 測試 -->
<id>test</id>
<properties>
<activatedProperties>test</activatedProperties>
</properties>
</profile>
<profile>
<!-- 生產 -->
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
</profiles>
- 打包
# -P 后的 參數是 profile 中的 id。 默認是 activeByDefault 為 true的 dev
# 測試打包
# springboot 配置文件 application-test.properoties 或 application-test.yaml 生效
mvn clean package -P test
# 生產打包
# springboot 配置文件 application-prod.properoties 或 application-prod.yaml 生效
mvn clean package -P prod
以上演示了 pom 自定義參數 activatedProperties ,被 springboot讀取的實例。
https://www.cnblogs.com/zeng1994/p/06917ed3b98677fa7a1b0f74de16c3be.html