maven profile实现多环境配置的示例
作者:松鼠陛下 时间:2023-09-24 12:02:57
环境:eclipse + spring mvc + maven
1、直接看图,把数据库的配置单独拿出来放在了resources_env目录下,三个不同环境参数不同,
2,在pom文件中添加配置
<profiles>
<profile>
<!-- 开发环境 -->
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<!-- 默认激活该profile节点-->
<activeByDefault>true</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>src/main/resources_env/dev</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<!-- 测试环境 -->
<id>qa</id>
<properties>
<env>qa</env>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources_env/qa</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<!-- 生产环境 -->
<id>online</id>
<properties>
<env>online</env>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources_env/online</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</profile>
</profiles>
说明:这个resources里面的路径对应上面文件路径,resources里面所有的配置加上各自环境的配置,
在引用jdbc.pro的地方如下:在datasource.xml中,
还有 新增的 evn那个包下面的所有文件都需要设置为资源文件,这个不必说 直接看图
3,maven设置要使用的环境:
项目右键-->maven-->Select Maven profiles ,选择一个环境,修改最好清理一下项目才生效,我之前没清理,发现没起作用。
4、然后运行项目就是你选择的环境了,或者直接导出war包,
其他的多环境配置同。
来源:https://blog.csdn.net/songshuguowang/article/details/86606210
标签:maven,profile,多环境配置
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解android系统的定制
2022-03-14 11:20:19
springmvc后台基于@ModelAttribute获取表单提交的数据
2023-08-05 12:29:35
![](https://img.aspxhome.com/file/2023/7/71657_0s.jpg)
java并发编程包JUC线程同步CyclicBarrier语法示例
2023-01-18 07:44:58
![](https://img.aspxhome.com/file/2023/7/63687_0s.png)
C#面向对象设计原则之接口隔离原则
2022-07-22 21:02:58
Android自定义DigitalClock控件实现商品倒计时
2023-07-17 20:13:28
![](https://img.aspxhome.com/file/2023/8/138988_0s.jpg)
Flutter Widgets MediaQuery控件屏幕信息适配
2023-06-29 04:48:21
![](https://img.aspxhome.com/file/2023/2/120092_0s.jpg)
java 线程中start方法与run方法的区别详细介绍
2023-08-23 20:41:31
java设计模式—静态代理模式(聚合与继承方式对比)
2022-08-08 05:35:58
![](https://img.aspxhome.com/file/2023/3/122013_0s.jpg)
Mybatis基于注解形式的sql语句生成实例代码
2023-03-07 03:48:11
Android Tween动画之RotateAnimation实现图片不停旋转效果实例介绍
2021-10-11 00:51:28
一文带你真正理解Java中的内部类
2023-11-24 20:42:07
![](https://img.aspxhome.com/file/2023/3/60073_0s.png)
spring cloud zuul修改请求url的方法
2022-09-03 01:44:19
Java 在游戏中探索数组二维数组
2023-07-01 10:04:04
![](https://img.aspxhome.com/file/2023/1/106191_0s.jpg)
C# TabControl控件中TabPage选项卡切换时的触发事件问题
2022-10-30 08:11:13
![](https://img.aspxhome.com/file/2023/9/85739_0s.png)
Scala可变参数列表,命名参数和参数缺省详解
2022-09-26 21:00:49
如何自动生成Mybatis的Mapper文件详解
2023-07-28 08:20:54
![](https://img.aspxhome.com/file/2023/8/57938_0s.jpg)
Java微信公众平台开发(14) 微信web开发者工具使用
2023-01-30 19:21:34
![](https://img.aspxhome.com/file/2023/0/67150_0s.jpg)
C#中数组初始化与数组元素复制的方法
2023-05-14 15:45:06
java实现sftp客户端上传文件以及文件夹的功能代码
2023-02-14 22:07:28
![](https://img.aspxhome.com/file/2023/0/61950_0s.png)
SpringAOP事务配置语法及实现过程详解
2023-12-27 21:26:16