Maven项目中经过profile定义使不一样环境使用不一样配置信息

profile能够让咱们定义一系列的配置信息,而后指定其激活条件。这样咱们就能够定义多个profile,而后每一个profile对应不一样的激活条件和配置信息,从而达到不一样环境使用不一样配置信息的效果。好比说,咱们能够经过profile定义在jdk1.5以上使用一套配置信息,在jdk1.5如下使用另一套配置信息;或者有时候咱们能够经过操做系统的不一样来使用不一样的配置信息,好比windows下是一套信息,linux下又是另一套信息,等等。linux

下面是不一样操做系统使用不一样配置信息的示例代码,pom.xml文件中添加:windows

 1 <profiles>
 2     <profile>
 3         <id>dev</id>
 4         <activation>
 5             <activeByDefault>true</activeByDefault>
 6             <os>
 7                 <family>Windows</family>
 8             </os>
 9         </activation>
10         <properties>
11             <filter.path>src\main\resources\config-dev.properties</filter.path>
12         </properties>
13     </profile>
14     <profile>
15         <id>production</id>
16         <activation>
17             <activeByDefault>false</activeByDefault>
18             <os>
19                 <family>Linux</family>
20             </os>
21         </activation>
22         <properties>
23             <filter.path>src\main\resources\config.properties</filter.path>
24         </properties>
25     </profile>
26 </profiles>
相关文章
相关标签/搜索