在開發中常有幾種模式
- dev:用于開發
- test:用于測試
- pro:用于生産
是以,在項目中常有一些配置檔案,如:
- appliancation-dev.properties
- appliancation-test.properties
- appliancation-pro.properties
是以,我們在打包的時候,需要注意指定那種環境是我們需要的,(通常在配置檔案中dev是預設的)。
第一步、在pom檔案中設定profileID及打包時需要替換的檔案
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>pro</id>
<properties>
<env>pro</env>
</properties>
</profile>
</profiles>
還有
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>application-${env}.properties</include>
</includes>
</resource>
</resources>
</build>
第二步
打包的時候使用“-P 環境名”即可将相應的配置檔案放入包中。
如: