springboot开发打包时,一般会有多个环境,dev,qa,prod等,配置文件大多雷同,只是方便开发切换,但是生成部署时产生的war包就无需这么多重复配置了,这时这些dev,qa的配置就不应该打入war包,这时就得用到profile属性

1、pom文件中添加profile节点,并在build下的resources节点添加打包过滤的配置文件规则

    <profiles>
<profile>
<id>dev</id>
<properties>
<profileActive>dev</profileActive>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>local</id>
<properties>
<profileActive>local</profileActive>
</properties>
</profile>
<profile>
<id>qa</id>
<properties>
<profileActive>qa</profileActive>
</properties>
</profile>
<profile>
<id>sdrmyy</id>
<properties>
<profileActive>sdrmyy</profileActive>
</properties>
</profile>
<profile>
<id>show</id>
<properties>
<profileActive>show</profileActive>
</properties>
</profile>
</profiles> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- maven打包插件 end -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>oip_hosp</warName>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>application-${profileActive}.yml</include>
<include>application.yml</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>

<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>

此节点需与配置文件后缀一一对应,如-dev

打包过滤配置文件规则也是用一个占位符进行占位,打包时也会通过maven传入参数进行替换

2、在主application.yml中配置一个动态属性进行占位,默认的分隔符是@属性名@,这个属性会通过maven打包时传入参数进行替换

3、maven打包时可以通过两种方式传入参数:

a)、通过 -D命令传入属性值profileActive,如:

clean install -Dmaven.test.skip=true -DprofileActive=dev

b)、通过-P命令指定profile环境,如:

clean package -P prod

或者直接通过插件可视化操作:

如果是idea的话,直接在右侧maven工具栏中勾选更方便:

4、本机运行时,一般通过指定profile属性,如

springboot创建多环境profile打包的更多相关文章

  1. Springboot 创建的maven获取resource资源下的文件的两种方式

    Springboot 创建的maven项目 打包后获取resource下的资源文件的两种方式: 资源目录: resources/config/wordFileXml/wordFileRecord.xm ...

  2. 通过maven profile 打包指定环境配置

    背景 最近换了个新公司接手了一个老项目,然后比较坑的是这个公司的项目都没有没有做多环境打包配置,每次发布一个环境都要手动的去修改配置文件.今天正好有空就来配置下. 解决这个问题的方式有很多,我这里挑选 ...

  3. SpringBoot实现多环境配置

    1.为什么需要配置多环境配置 在实际的开发中,我们往往需要在不同的环境中使用不同的数据库.缓存配置,如果使用同一套配置文件,在不同环境部署的时候手动去修改配置文件,会使部署变得很繁琐.使用多环境配置文 ...

  4. springboot maven 多环境配置

    1.使用Intellij IDEA创建Spring Boot和Maven项目 2.Spring Boot项目下application.yaml(yaml支持中文)或者application.prope ...

  5. SpringBoot Profiles 多环境配置及切换

    目录 前言 默认环境配置 多环境配置 多环境切换 小结 前言 大部分情况下,我们开发的产品应用都会根据不同的目的,支持运行在不同的环境(Profile)下,比如: 开发环境(dev) 测试环境(tes ...

  6. maven根据不同的运行环境,打包不同的配置文件

    使用maven管理项目中的依赖,非常的方便.同时利用maven内置的各种插件,在命令行模式下完成打包.部署等操作,可方便后期的持续集成使用. 但是每一个maven工程(比如web项目),开发人员在开发 ...

  7. springboot创建maven多模块项目

    SpringBoot创建maven多模块项目 项目结构 该项目名称为springboot-maven-multi,由springboot-maven-multi.user-dao.user-domai ...

  8. maven根据不同的运行环境,打包不同的配置文件(转载)

    使用maven管理项目中的依赖,非常的方便.同时利用maven内置的各种插件,在命令行模式下完成打包.部署等操作,可方便后期的持续集成使用. 但是每一个maven工程(比如web项目),开发人员在开发 ...

  9. 利用springboot创建多模块项目

    本文旨在用最通俗的语言讲述最枯燥的基本知识 最近要对一个不大不小的项目进行重构,用spring觉得太过于繁琐,用cloud又有觉得过于庞大,维护的人手不够:权衡之下,最终选了springboot作为架 ...

随机推荐

  1. 清空select下拉框的方法

    $("#search").find("option").remove(); //或者 $("#search").empty();

  2. Eclipse修改背景颜色

    windows->peferences->General->Editors->Text EditorAppearance color options:选择Background ...

  3. 1.2_php验证码

    使用php生成动态的验证码图片 <!DOCTYPE html> <html> <head> <meta charset="utf-8"&g ...

  4. 160720、SSM-Shiro使用详解

    前言 相比有做过企业级开发的童鞋应该都有做过权限安全之类的功能吧,最先开始我采用的是建用户表,角色表,权限表,之后在拦截器中对每一个请求进行拦截,再到数据库中进行查询看当前用户是否有该权限,这样的设计 ...

  5. 剩余参数(rest arguments) Mixin

    Mixin – Pug 中文文档 https://pug.bootcss.com/language/mixins.html 混入 Mixin 混入是一种允许您在 Pug 中重复使用一整个代码块的方法. ...

  6. use getters and setters Learning PHP Design Patterns

    w Learning PHP Design Patterns Much of what passes as OOP misuses getters and setters, and making ac ...

  7. Pycharm选中代码无法Backspace直接删除

    现象 如图,选中代码后,按习惯来说,直接Backspace就可以删除被选中代码. 但选中后再按“Backspace”,只会改变(扩选)选中范围. 解决 点击“工具栏”里的“Tool”,去掉勾选的Vim ...

  8. python3 基础数据类型

    一.基础数据类型分类 python的数据类型主要包括以下几种: 1.数字 2.字符串 3.列表 4.字典 5.元组 6.集合 1.数字 int 数字主要是用于计算用的,使用方法并不多 #bit_len ...

  9. python小知识点复习

    join 与 split 对应,join传入的列表只包含字符串卡类型 字典 dic = {'x':1, 'y':2, 'x':3} print(dic) # {'x': 3, 'y': 2} 重复的k ...

  10. Giraph执行报错,Error: Exceeded limits on number of counters - Counters=120 Limit=120, exiting...

    HamaWhite 原创,转载请注明出处.欢迎大家增加Giraph 技术交流群: 228591158 1. 近日用Giraph跑大数据的SSSP时,遇到例如以下错误: org.apache.hadoo ...