打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
maven多环境打包配置

1、将公共的配置文件放在resources里面,开发环境、生产环境、测试环境分别放在resources.dev、resources.test、resources.prod

2、在pom.xml设置

  1. <build>
  2. <resources>
  3. <resource>
  4. <!--把相对应的独特资源(dev,test,prod这三种的一种)声明,排除jsp文件-->
  5. <directory>src/main/resources.${deploy.type}</directory>
  6. <excludes>
  7. <exclude>*.jsp</exclude>
  8. </excludes>
  9. </resource>
  10. <resource>
  11. <!--声明公共资源-->
  12. <directory>src/main/resources</directory>
  13. </resource>
  14. </resources>
  15. </build>
  16. <!--分别设置开发,测试,生产环境-->
  17. <profiles>
  18. <profile>
  19. <id>dev</id>
  20. <activation>
  21. <activeByDefault>true</activeByDefault>
  22. </activation>
  23. <properties>
  24. <deploy.type>dev</deploy.type>
  25. </properties>
  26. </profile>
  27. <profile>
  28. <id>test</id>
  29. <properties>
  30. <deploy.type>test</deploy.type>
  31. </properties>
  32. </profile>
  33. <profile>
  34. <id>prod</id>
  35. <properties>
  36. <deploy.type>prod</deploy.type>
  37. </properties>
  38. </profile>
  39. </profiles>

3、使用maven进行多环境打包

-Dmaven.test.skip=true 为测试打包和测试编译,-P后面接的是所需要打包环境的id,如dev开发环境,test测试环境,如果不写-P,默认为dev即开发环境

mvn clean package -Dmaven.test.skip=true -Ptest

4、当开发的时候,联合本地tomcat使用方法

1、intellij idea

如图所示,选上对应的环境,然后运行tomcat即可


2、eclipse

右键项目配置,然后选上maven,输入你需要的环境id,如dev


以上内容转自(炎发灼眼大哥成)

springboot 配置多资源方式,建立不同的环境的资源application.properties是公共资源


在application添加环境替换设置,deploy.type为pom.xml配置的多环境

spring.profiles.active=@deploy.type@

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
嗯,挺全乎儿的,Spring Boot 多环境配置都在这儿了,你喜欢哪一种呢?
maven打包 含src下的xml文件
orbeon form 的配置介绍
[Spring Boot 系列] 集成maven和Spring boot的profile功能
Maven中使用profile和filtering进行属性过滤
UC头条:Springboot使用Nacos做配置中心)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服