经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 软件/图像 » Maven » 查看文章
maven profile实现多环境配置的示例
来源:jb51  时间:2021/1/25 15:12:32  对本文有异议

环境:eclipse + spring mvc + maven

1、直接看图,把数据库的配置单独拿出来放在了resources_env目录下,三个不同环境参数不同,

2,在pom文件中添加配置 

  1. <profiles>
  2. <profile>
  3. <!-- 开发环境 -->
  4. <id>dev</id>
  5. <properties>
  6. <env>dev</env>
  7. </properties>
  8. <activation>
  9. <!-- 默认激活该profile节点-->
  10. <activeByDefault>true</activeByDefault>
  11. </activation>
  12. <build>
  13. <resources>
  14. <resource>
  15. <directory>src/main/resources_env/dev</directory>
  16. </resource>
  17. <resource>
  18. <directory>src/main/resources</directory>
  19. </resource>
  20. </resources>
  21. </build>
  22. </profile>
  23. <profile>
  24. <!-- 测试环境 -->
  25. <id>qa</id>
  26. <properties>
  27. <env>qa</env>
  28. </properties>
  29. <build>
  30. <resources>
  31. <resource>
  32. <directory>src/main/resources_env/qa</directory>
  33. </resource>
  34. <resource>
  35. <directory>src/main/resources</directory>
  36. </resource>
  37. </resources>
  38. </build>
  39. </profile>
  40. <profile>
  41. <!-- 生产环境 -->
  42. <id>online</id>
  43. <properties>
  44. <env>online</env>
  45. </properties>
  46. <build>
  47. <resources>
  48. <resource>
  49. <directory>src/main/resources_env/online</directory>
  50. </resource>
  51. <resource>
  52. <directory>src/main/resources</directory>
  53. </resource>
  54. </resources>
  55. </build>
  56. </profile>
  57. </profiles>

说明:这个resources里面的路径对应上面文件路径,resources里面所有的配置加上各自环境的配置,

在引用jdbc.pro的地方如下:在datasource.xml中,

还有 新增的 evn那个包下面的所有文件都需要设置为资源文件,这个不必说 直接看图

3,maven设置要使用的环境:

项目右键-->maven-->Select Maven profiles ,选择一个环境,修改最好清理一下项目才生效,我之前没清理,发现没起作用。

 

4、然后运行项目就是你选择的环境了,或者直接导出war包,

  其他的多环境配置同。

到此这篇关于maven profile实现多环境配置的示例的文章就介绍到这了,更多相关maven profile多环境配置内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号