pom 內容
<build>
<filters>
<filter>src/main/filters/filter-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>develop</id>
<properties>
<env>develop</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<env>product</env>
</properties>
</profile>
</profiles>
src/main/filters/filter-develop.properties內容(輔助)
jdbc.url=jdbc:mysql://localhost:3306/dev?characterEncoding=utf-8
jdbc.username=rootdev
jdbc.password=rootdev
src/main/filters/filter-test.properties內容(輔助)
jdbc.url=jdbc:mysql://111.111.111.111:3306/test?characterEncoding=utf-8
jdbc.username=roottest
jdbc.password=roottest
src/main/filters/filter-product.properties內容(輔助)
jdbc.url=jdbc:mysql://121.121.121.121:3306/product?characterEncoding=utf-8
jdbc.username=rootproduct
jdbc.password=rootproduct
src/main/resources/jdbc.properties內容(主要)
url=${jdbc.url}
username=${jdbc.username}
password=${jdbc.password}
maven命令(主要)
mvn package -Pproduct
mvn package -Ptest
mvn package -Pdevelop