一、介绍
我们项目打包的时候需要选择具体引用哪个配置文件,product?test?dev?
而<profiles>就是指定具体的配置文件的。
二、配置案例
<!-- profile begin -->
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>APP_ENV</name>
<value>dev</value>
</property>
</activation>
<properties>
<profile.env.name>env.dev.properties</profile.env.name>
</properties>
</profile>
<profile>
<id>test</id>
<activation>
<property>
<name>APP_ENV</name>
<value>test</value>
</property>
</activation>
<properties>
<profile.env.name>env.test.properties</profile.env.name>
</properties>
</profile>
<profile>
<id>product</id>
<activation>
<property>
<name>APP_ENV</name>
<value>product</value>
</property>
</activation>
<properties>
<profile.env.name>env.product.properties</profile.env.name>
</properties>
</profile>
<profile>
<id>product_cron</id>
<activation>
<property>
<name>APP_ENV</name>
<value>product_cron</value>
</property>
</activation>
<properties>
<profile.env.name>env.product_cron.properties</profile.env.name>
</properties>
</profile>
</profiles>
<!-- profile end -->
三、引用
方式一:通过-P引用
打包时执行mvn clean package -P test将触发test环境的profile配置
相对应的:
mvn clean package -P dev 触发env.dev.properties
mvn clean package -P product 触发 env.product.properties
方式二:通过-D引用
-D代表(Properties属性)
如上对应的property的name为APP_ENV,因此可以使用如下命令
mvn clean package -DAPP_ENV=test 将触发test环境的profile配置
mvn clean package -DAPP_ENV=dev 触发env.dev.properties
mvn clean package -DAPP_ENV=product 触发 env.product.properties