maven多环境配置(用于不同场景下切换数据库)
maven常用命令
- compile :编译
- clean:清理
- test:测试
- package:打包
- install:安装
maven多环境配置步骤
1.在pom中指定不同环境的信息
<!-- 多环境配置 -->
<profiles>
<profile>
<id>dev</id> <!-- 开发环境 -->
<properties>
<host>localhost</host>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id> <!-- 测试环境 -->
<properties>
<host>192.168.1.100</host>
</properties>
</profile>
<profile>
<id>pro</id> <!-- 生产环境 -->
<properties>
<host>10.12.111.222</host>
</properties>
</profile>
</profiles>
2.在pom中加以下代码,表示在资源拷贝时,替换 ${} , 替换为环境实际值
<build>
<resources>
<resource>
<!-- 表示 src/main/resources 下所有资源时,执行 ${} 占位符的替换操作 -->
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
3.更改jdbc.properties配置文件
4.设置选用的环境
5.选择步骤4对应name的设置,执行不一样的结果不一样