思路:maven支持profile功能,当使用maven profile打包时,可以打包指定目录和指定文件,且可以修改文件中的变量。spring boot也支持profile功能,只要在application.properties文件中指定spring.profiles.active=xxx 即可,其中xxx是一个变量,当maven打包时,修改这个变量即可。

1。配置maven 的profile

    <!-- 不同环境查找不同配置文件 -->
<profiles>
<profile>
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
<maven.test.skip>true</maven.test.skip>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>sit</id>
<properties>
<profiles.active>sit</profiles.active>
<maven.test.skip>true</maven.test.skip>
</properties>
</profile>
<profile>
<id>prd1</id>
<properties>
<profiles.active>prd1</profiles.active>
<maven.test.skip>true</maven.test.skip>
<scope.jar>provided</scope.jar>
</properties>
</profile>
<profile>
<id>prd2</id>
<properties>
<profiles.active>prd2</profiles.active>
<maven.test.skip>true</maven.test.skip>
<scope.jar>provided</scope.jar>
</properties>
</profile>
</profiles>

其中profiles.active是我们定义的一个变量,可通过mvn命令指定,别人也能访问

在build中配置可修改可访问资源文件

        <resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application-dev.properties</exclude>
<exclude>application-sit.properties</exclude>
<exclude>application-prd1.properties</exclude>
<exclude>application-prd2.properties</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application-${profiles.active}.properties</include>
<include>application.properties</include>
</includes>
</resource>
</resources>

其中  ${profiles.active}是上面profile中指定的变量

2.配置springboot的profile

  这是通过spring.profiles.active指定

  在application.properties中指定spring.profiles.active=@profiles.active@,即可这样就将maven与springboot的profile结合了

3.打包命令:mvn clean package -Dmaven.test.skip=true -P prod -e

集成maven和Spring boot的profile功能的更多相关文章

  1. [Spring Boot 系列] 集成maven和Spring boot的profile功能

    由于项目的需要, 今天给spirng boot项目添加了profile功能.再网上搜索了一圈,也没有找到满意的参考资料,其实配置并不难,就是没有一个one stop(一站式)讲解的地方,所以有了写这篇 ...

  2. 集成maven和Spring boot的profile 专题

    maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...

  3. [Spring Boot 系列] 集成maven和Spring boot的profile 专题

    maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...

  4. 集成maven和Spring boot的profile

    如果在配置中勾选了多套配置,则以pom.xml文件中 profiles中  配置 最后一个配置为准. maven中配置profile节点: <project> .... <profi ...

  5. 004-集成maven和Spring boot的profile功能打包

    参考地址:https://blog.csdn.net/lihe2008125/article/details/50443491 一.主要目标 1.通过mvn在命令行中打包时,可以指定相应的profil ...

  6. Spring boot 的profile功能如何实现多环境配置自动切换

    通常服务端应用开发需要经过以下几个流程: 开发 -> 测试 -> RC验证 -> 上线 这就涉及到四个不同的环境,开发环境.测试环境.RC环境以及生产环境,为了避免不同环境之间相互干 ...

  7. 借助Maven入手Spring Boot第一个程序

    目前网上有不少Spring Boot的入门文章,都很有帮助,本人最近在深入学习Spring Cloud,在搭建第一个Hello World程序时,感觉对于新手而言,介绍文章怎么详细都不为过,因为其中坑 ...

  8. Maven 搭建spring boot多模块项目(附源码),亲测可以,感谢原创

    原创地址:https://segmentfault.com/a/1190000005020589 我的DEMO码云地址,持续添加新功能: https://gitee.com/itbase/Spring ...

  9. Spring Boot实现文件下载功能

    我们只需要创建一个控制器(Controler)文件,即Controller目录下的File_Download.java,其完整目录如下: @Controller public class File_D ...

随机推荐

  1. 基于.NET Standard的分布式自增ID算法--Snowflake代码实现

    概述 上篇文章介绍了3种常见的Id生成算法,本篇主要介绍如何使用C#实现Snowflake. 基础字段 /// <summary> /// 工作节点Id(长度为5位) /// </s ...

  2. Mysql_临时表

    CREATE TEMPORARY TABLE test_info ( test_name ) NOT NULL, test_totail ,) NOT NULL DEFAULT 0.00, test_ ...

  3. 手机Gmail上用Exchange协议配置收发QQ邮箱

    1.开启Exchange服务  2.生成授权码(登录密码)  3."服务器"填入ex.qq.com

  4. 用HackRF和Gqrx来听FM广播

    本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...

  5. jmeter学习(1)基础支持+安装部署

    1. Apache jmeter 是100%的java桌面应用程序 支持的协议有:WEB-HTTP/HTTPS   , SOAP,   FTP,  JDBC,  LDAP, MAIL, MongoDB ...

  6. #个人博客作业Week1----关于软件和软件工程的出现

    1.软件工程这个词如何出现的? 数学与电脑科学先锋Margaret Hamilton在开发阿波罗11号软件的期间发明的,目的是将软件与硬件还有其他工程学类做出区别,为软件以及那些发明者争取应有的正统性 ...

  7. 第三次Scrum meeting

    第三次Scrum meeting 会议主要内容: 测试方面:确定测试的各个环节以及测试的相关要求,完成初步的功能测试.同时在测试时仔细记录相应错误信息,并进行备注. 沟通方面:同Dream团队(学霸前 ...

  8. 第二个spring冲刺第6天

    今天的进展不多,对代码重新进行了整合,看起了比较简洁

  9. 读C#程序最小公倍数答案就是:2123581660200

    阅读下面程序,请回答如下问题: 问题1:这个程序要找的是符合什么条件的数? 问题2:这样的数存在么?符合这一条件的最小的数是什么? 问题3:在电脑上运行这一程序,你估计多长时间才能输出第一个结果?时间 ...

  10. [转帖] sparkdev 的 博客 systemd

    从 init 系统说起 https://www.cnblogs.com/sparkdev/p/8448237.html systemd的内容 需要学习下. linux 操作系统的启动首先从 BIOS ...