集成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 ...
随机推荐
- Magento 总结
ZEND EAV 速度 作者:李淼链接:https://www.zhihu.com/question/20656910/answer/25793452来源:知乎著作权归作者所有.商业转载请联系作者获得 ...
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
- PAT甲题题解-1128. N Queens Puzzle (20)-做了一个假的n皇后问题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789810.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- [转帖] 一文看懂:"边缘计算"究竟是什么?为何潜力无限?
一文看懂:"边缘计算"究竟是什么?为何潜力无限? 转载cnbeta 云计算 雾计算 边缘计算... 知名创投调研机构CB Insights撰文详述了边缘计算的发展和应用前景 ...
- NGINX.conf配置文件支持pathinfo
# power by www.php.cn #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/e ...
- Java之工具类:判断对象是否为空或null
import java.lang.reflect.Array; import java.util.Collection; import java.util.Map; /** * 判断对象是否为空或nu ...
- 一本通1622Goldbach’s Conjecture
1622:Goldbach’s Conjecture 时间限制: 1000 ms 内存限制: 524288 KB [题目描述] 原题来自:Ulm Local,题面详见:POJ 2262 ...
- 我为什么放弃MySQL?选择了MongoDB
最近有个项目的功能模块,为了处理方便,需要操作集合类型的数据以及其他原因.考虑再三最终决定放弃使用MySQL,而选择MongoDB. 两个数据库,大家应该都不陌生.他们最大的区别就是MySQL为关系型 ...
- 【刷题】LOJ 6015 「网络流 24 题」星际转移
题目描述 由于人类对自然资源的消耗,人们意识到大约在 2300 年之后,地球就不能再居住了.于是在月球上建立了新的绿地,以便在需要时移民.令人意想不到的是,2177 年冬由于未知的原因,地球环境发生了 ...
- 【模板】BM + CH(线性递推式的求解,常系数齐次线性递推)
这里所有的内容都将有关于一个线性递推: $f_{n} = \sum\limits_{i = 1}^{k} a_{i} * f_{n - i}$,其中$f_{0}, f_{1}, ... , f_{k ...