集成maven和Spring boot的profile功能
思路: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功能的更多相关文章
- [Spring Boot 系列] 集成maven和Spring boot的profile功能
由于项目的需要, 今天给spirng boot项目添加了profile功能.再网上搜索了一圈,也没有找到满意的参考资料,其实配置并不难,就是没有一个one stop(一站式)讲解的地方,所以有了写这篇 ...
- 集成maven和Spring boot的profile 专题
maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...
- [Spring Boot 系列] 集成maven和Spring boot的profile 专题
maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...
- 集成maven和Spring boot的profile
如果在配置中勾选了多套配置,则以pom.xml文件中 profiles中 配置 最后一个配置为准. maven中配置profile节点: <project> .... <profi ...
- 004-集成maven和Spring boot的profile功能打包
参考地址:https://blog.csdn.net/lihe2008125/article/details/50443491 一.主要目标 1.通过mvn在命令行中打包时,可以指定相应的profil ...
- Spring boot 的profile功能如何实现多环境配置自动切换
通常服务端应用开发需要经过以下几个流程: 开发 -> 测试 -> RC验证 -> 上线 这就涉及到四个不同的环境,开发环境.测试环境.RC环境以及生产环境,为了避免不同环境之间相互干 ...
- 借助Maven入手Spring Boot第一个程序
目前网上有不少Spring Boot的入门文章,都很有帮助,本人最近在深入学习Spring Cloud,在搭建第一个Hello World程序时,感觉对于新手而言,介绍文章怎么详细都不为过,因为其中坑 ...
- Maven 搭建spring boot多模块项目(附源码),亲测可以,感谢原创
原创地址:https://segmentfault.com/a/1190000005020589 我的DEMO码云地址,持续添加新功能: https://gitee.com/itbase/Spring ...
- Spring Boot实现文件下载功能
我们只需要创建一个控制器(Controler)文件,即Controller目录下的File_Download.java,其完整目录如下: @Controller public class File_D ...
随机推荐
- sonarqube扫描安卓代码
代码才用https://github.com/liwanlei/bilibili-android-client 配置: build.gralde配置 buildscript { repositorie ...
- 利用matlab写一个简单的拉普拉斯变换提取图像边缘
可以证明,最简单的各向同性微分算子是拉普拉斯算子.一个二维图像函数 f(x,y) 的拉普拉斯算子定义为 其中,在 x 方向可近似为 同理,在 y 方向上可近似为 于是 我们得到满足以上三个 ...
- 人类又被AI碾压,这次是星际争霸
还记得2017年,那个血洗围棋界的“阿尔法狗”吗? 这个由谷歌旗下 DeepMind 公司开发的 AI ,对阵世界顶尖围棋选手,打出完全碾压式的战绩: AlphaGo vs. 樊麾 - 5 : ...
- 了不起的Node.js--之二
安装模块 使用NPM包管理器可以让你轻松对模块进行管理,它会下载指定的包.解决包的依赖.进行测试脚本及安装命令行脚本. 安装二进制工具包 有的项目分发的是Node编写的命令行工具.这个时候,安装时要增 ...
- 一个http请求发送到后端的详细过程
我们来看当我们在浏览器输入http://www.mycompany.com:8080/mydir/index.html,幕后所发生的一切. 首先http是一个应用层的协议,在这个层的协议,只是一种通讯 ...
- python3与python2使用python原生SimpleHTTPRequestHandler
python3 使用时如下: #!/usr/bin/env python3 #coding=utf-8 from http.server import SimpleHTTPRequestHandler ...
- 1084. Broken Keyboard (20)-水题
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...
- 桌面输入法评测报告 之 搜狗拼音输入法vs必应拼音输入法
输入法是电脑用户不可或缺的软件,它几乎无时无刻不陪伴在使用者的身旁.一个优秀的输入法,应该满足客户对使用体验以及效率的需求.我们小队的任务便是对当今最为常用的两种输入法: 搜狗拼音输入法和必应拼音输入 ...
- 2-Fifteenth Scrum Meeting-20151215
任务安排 成员 今日完成 明日任务 闫昊 修复bug 写完学习进度记录的数据库操作 唐彬 编写与服务器交互的代码 编写与服务器交互的代码 史烨轩 获取视频url 余帆 修复bug 本地路径的 ...
- 《Linux内核分析》第一周学习小结 计算机是如何工作的?
<Linux内核分析>第一周.计算机是如何工作的? 20135204 郝智宇 一.存储程序计算机工作模型 1. 冯诺依曼体系结构: 数字计算机的数制采用二进制:计算机应该按照程 ...