Spring Boot系列之-profile

Spring Boot profile用于分离不同环境的参数配置,通过spring.profile.active参数设置使用指定的profile。
在Spring Boot中应用程序配置可以使用2种格式:application.properties 或者 application.yml。
以".yml"格式为例说明:
在项目配置中,通常会存在如下几个配置文件:
application.yml: 用于公共参数配置
application-dev.yml: 用于开发环境配置
application-test.yml: 用于测试环境配置
application-prod.yml: 用于生产环境配置
在application.yml中设置:
spring:
profile:
active: dev | test | prod # 设置profile参数
例如:当指定spring.profile.active = dev 后,程序启动时将加载application.yml 和 application-dev.yml 中的配置参数。
另外,如果项目使用maven进行构建,为了打包时只打包相应的application配置文件,需要通过maven的profile定义来实现。
<!-- 定义环境 -->
<profiles>
<!-- 开发环境 -->
<profile>
<id>dev</id>
<properties>
<!-- 定义profileActive属性 -->
<profileActive>dev</profileActive>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile> <!-- 测试环境 -->
<profile>
<id>test</id>
<properties>
<profileActive>test</profileActive>
</properties>
</profile> <!-- 生产环境 -->
<profile>
<id>prod</id>
<properties>
<profileActive>prod</profileActive>
</properties>
</profile>
</profiles> <build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application.yml</exclude>
<exclude>application-dev.yml</exclude>
<exclude>application-test.yml</exclude>
<exclude>application-prod.yml</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.yml</include>
<include>application-${profileActive}.yml</include>
</includes>
</resource>
</resources>
<build>
【参考】
http://blog.csdn.net/lihe2008125/article/details/50443491
http://www.jianshu.com/p/01efe59d6a64
http://blog.javachen.com/2016/02/22/profile-usage-in-spring-boot.html
Spring Boot系列之-profile的更多相关文章
- [Spring Boot 系列] 集成maven和Spring boot的profile功能
由于项目的需要, 今天给spirng boot项目添加了profile功能.再网上搜索了一圈,也没有找到满意的参考资料,其实配置并不难,就是没有一个one stop(一站式)讲解的地方,所以有了写这篇 ...
- [Spring Boot 系列] 集成maven和Spring boot的profile 专题
maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...
- Spring Boot 系列总结
Spring Boot 系列总结 1.SpringBoot自动装配 1.1 Spring装配方式 1.2 Spring @Enable 模块驱动 1.3 Spring 条件装配 2.自动装配正文 2. ...
- Spring Boot 系列教程19-后台验证-Hibernate Validation
后台验证 开发项目过程中,后台在很多地方需要进行校验操作,比如:前台表单提交,调用系统接口,数据传输等.而现在多数项目都采用MVC分层式设计,每层都需要进行相应地校验. 针对这个问题, JCP 出台一 ...
- Spring Boot 系列教程18-itext导出pdf下载
Java操作pdf框架 iText是一个能够快速产生PDF文件的java类库.iText的java类对于那些要产生包含文本,表格,图形的只读文档是很有用的.它的类库尤其与java Servlet有很好 ...
- Spring Boot 系列教程17-Cache-缓存
缓存 缓存就是数据交换的缓冲区(称作Cache),当某一硬件要读取数据时,会首先从缓存中查找需要的数据,如果找到了则直接执行,找不到的话则从内存中找.由于缓存的运行速度比内存快得多,故缓存的作用就是帮 ...
- Spring Boot 系列教程16-数据国际化
internationalization(i18n) 国际化(internationalization)是设计和制造容易适应不同区域要求的产品的一种方式. 它要求从产品中抽离所有地域语言,国家/地区和 ...
- Spring Boot 系列教程15-页面国际化
internationalization(i18n) 国际化(internationalization)是设计和制造容易适应不同区域要求的产品的一种方式. 它要求从产品中抽离所有地域语言,国家/地区和 ...
- Spring Boot 系列教程14-动态修改定时任务cron参数
动态修改定时任务cron参数 不需要重启应用就可以动态的改变Cron表达式的值 不能使用@Scheduled(cron = "${jobs.cron}")实现 DynamicSch ...
随机推荐
- spark yarn 提交作业
spark提交作业命令: ./spark-submit --master yarn --deploy-mode cluster --class com.zjlantone.hive.SparkOper ...
- C# 遍历 enum 枚举
foreach (Suit suit in (Suit[]) Enum.GetValues(typeof(Suit))) { } 注意:强制转换(Suit[])不是必需的,但确实使代码快0.5 ns.
- git中常用命令
1.全局安装git Git-2.11.1-64-bit() //配置gitgit config --global user.name "您的git账号名"git config -- ...
- PDB符号文件浏览工具介绍
一.SymView SymView工具用来显示符号文件中包含的符号表和符号数据.目前支持微软的Visual C/C++和C#编译器产生的DBG格式的符号文件和PDB格式的符号文件. SymView提供 ...
- Luogu5591 小猪佩奇学数学 【单位根反演】
题目链接:洛谷 \[ Ans=\frac{1}{k}(\sum_{i=0}^n\binom{n}{i}p^ii-\sum_{i=0}^n\binom{n}{i}p^i(i \ \mathrm{mod} ...
- 洛谷P2312解方程题解
题目 暴力能得\(30\),正解需要其他的算法操作,算法操作就是用秦九韶算法来优化. 秦九韶算法就是求多项式的值时,首先计算最内层括号内一次多项式的值,然后由内向外逐层计算一次多项式的值,然后就将求\ ...
- 【CSP模拟赛】天才绅士少女助手克里斯蒂娜(线段树&读入优化&输出优化)
题面描述 红莉栖想要弄清楚楼下天王寺大叔的显像管电视对“电话微波炉(暂定)”的影响.选取显像管的任意一个平面,一开始平面内有个n电子,初始速度分别为vi,定义飘升系数为 $$\sum_{1\leqsl ...
- Failed opening libc!的解决方法
方法来源: http://www.cfd-online.com/Forums/fluent/135879-setting-process-affinity-failed-opening-libc.ht ...
- ICEM-带把圆环
原视频下载地址:https://pan.baidu.com/s/1pKSXyR5 密码: dynm
- tecplot-云图中显示等值线的值
原版视频下载地址:https://yunpan.cn/cx6IQkkYKIB99 访问密码 a3ee