思路: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. 设计模式 笔记 模版方法模式 Template Method

    //---------------------------15/04/28---------------------------- //TemplateMethod 模版方法模式----类行为型模式 ...

  2. Java设置PPT的扇形图,与内嵌Excel联动

    /** * 设置饼图的主方法 * @param slide 图表 * @param index 图标位置 * @param data 需要设置的数据 * @param titles 关联Excel的标 ...

  3. OpenCV操作像素

    在了解了图像的基础知识和OpenCV的基础知识和操作以后,接下来我们要做的就对像素进行操作,我们知道了图像的本质就是一个矩阵,那么一个矩阵中存储了那么多的像素,我们如何来操作呢?下面通过几个例子来看看 ...

  4. Unity协程Coroutine使用总结和一些坑

    原文摘自 Unity协程Coroutine使用总结和一些坑 MonoBehavior关于协程提供了下面几个接口: 可以使用函数或者函数名字符串来启动一个协程,同时可以用函数,函数名字符串,和Corou ...

  5. 上云利器,K8S应用编排设计器之快到极致

    前言在前面的文章中,我们已经提到,华为云有一个上云利器:应用编排设计器.作为华为云应用编排服务与用户沟通的桥梁,设计器坚持用户体验至上的理念,以图形化方式,在鼠标点击之间,助力企业快速上云.优质的交互 ...

  6. dtcp格式定义

    common name type optional comment id string y Content id version string y DTCP version. "1.0&qu ...

  7. mac 安装 tomcat 配置

    前面的话:记录下 Mac 安装配置 Tomcat 过程 1. 下载安装 Tomcat 下载 Tomcat 地址(官方地址):https://tomcat.apache.org/download-80. ...

  8. Alpha 答辩总结

    前言 作业发布 组长 成员 贡献比例 ★ 530 雨勤 23% 311 旭 23% 403 俊 18% 223 元 23% 437 海辉 13% 10天 Alpha 冲刺站立会议博客链接汇总 Alph ...

  9. JAVA面对对象(二)——继承、方法的覆写

    1.继承就是基于已存在的类构造一个新类,继承已存在的类就能复用类的方法和属性,并且能够添加新的方法和属性.也就是子类和父类 2.一个父类可以拥有多个子类,一个子类只允许有一个父类 3.用extends ...

  10. Activiti源码:StandaloneInMemProcessEngineConfiguration与SpringProcessEngineConfiguration

    activiti-engine-5.22.0-sources.jar package org.activiti.engine.impl.cfg; StandaloneInMemProcessEngin ...