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

springboot系列之-profile的更多相关文章

  1. SpringBoot系列之外部配置用法简介

    SpringBoot系列之外部配置用法简介 引用Springboot官方文档的说法,官方文档总共列举了如下用法: 1.Devtools global settings properties on yo ...

  2. SpringBoot系列——利用系统环境变量与配置文件的分支选择实现“智能部署”

    前言 通过之前的博客:SpringBoot系列——jar包与war包的部署,我们已经知道了如果实现项目的简单部署,但项目部署的时候最烦的是什么?修改成发布环境对应的配置!数据库连接地址.Eureka注 ...

  3. SpringBoot系列: Maven多项目管理

    这篇是 maven 项目管理的第二篇, 讲解使用 maven 进行多个项目管理, 之前有一篇是 maven 的基础知识. SpringBoot系列: Eclipse+Maven环境准备 一个完整的解决 ...

  4. SpringBoot系列——Logback日志,输出到文件以及实时输出到web页面

    前言 SpringBoot对所有内部日志使用通用日志记录,但保留底层日志实现.为Java Util Logging.Log4J2和Logback提供了默认配置.在不同的情况下,日志记录器都预先配置为使 ...

  5. SpringBoot系列之@Conditional注解用法简介

    SpringBoot系列之@Conditional注解用法简介 引用Spring官方文档的说法介绍一下@Conditional注解:Spring5.0.15版本@Conditional注解官方文档 @ ...

  6. SpringBoot系列之集成logback实现日志打印(篇二)

    SpringBoot系列之集成logback实现日志打印(篇二) 基于上篇博客SpringBoot系列之集成logback实现日志打印(篇一)之后,再写一篇博客进行补充 logback是一款开源的日志 ...

  7. SpringBoot系列之profles配置多环境(篇二)

    SpringBoot系列之profles配置多环境(篇二) 继续上篇博客SpringBoot系列之profles配置多环境(篇一)之后,继续写一篇博客进行补充 写Spring项目时,在测试环境是一套数 ...

  8. SpringBoot系列(十三)统一日志处理,logback+slf4j AOP+自定义注解,走起!

    往期精彩推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件详解 SpringBoot系列(四)we ...

  9. springBoot系列教程07:异常捕获

    发生异常是很正常的事,异常种类也是千奇百怪,发生异常并不可怕,只要正确的处理,并正确的返回错误信息并无大碍,如果不进行捕获或者处理,分分钟服务器宕机是很正常的事 所以处理异常时,最基本的要求就是发生异 ...

随机推荐

  1. faster alter table add column

    Create a new table (using the structure of the current table) with the new column(s) included. execu ...

  2. 17.KVM安装之虚拟磁盘,安装脚本

    1.创建磁盘 vm.list 指定虚拟磁盘名称和主机名 create_vm.sh    #创建vm.list中的虚拟磁盘,并指定大小100G #!/bin/bash VM_DIR="/opt ...

  3. js判断鼠标进入以及离开容器的方向

      (注:以下代码涉及到jQuery,建议前端大牛绕路~~~) 1.遇到的问题      如图当鼠标右箭头位置上下移动的时候  下面的城市列表容器不能隐藏. 2.方法: 网上搜了些前端大牛们的解决办法 ...

  4. c语言期末复习题

    代码参考:<K&R> 1.单词计数 #include<stdio.h> #define IN 1 #define OUT 0 main() { int c, state ...

  5. fifter常见的运用场景

    没配置过滤器 package servlet; import java.io.IOException; import javax.servlet.ServletException; import ja ...

  6. Oracle_双机备份

    1.dataguard http://jingyan.baidu.com/article/f96699bb956ef2894e3c1b39.html http://blog.itpub.net/262 ...

  7. jquery中通过全局变量来禁止多次ajax请求

    var ajaxstate=false;//定义全局变量,通过这个变量来获得当前的ajax状态 $(function(){ $(document).ajaxStart(function(){ $(&q ...

  8. Ubuntu中设置静态IP和DNS

    在Ubuntu中设置静态IP共两步:1>设置IP:2>设置DNS1>设置IP    编辑 /etc/network/interface文件:       sudo vi /etc/n ...

  9. Using Spring Boot without the parent POM

    Using Spring Boot without the parent POM: 问题 spring boot项目一般情况下的parent如下: <parent> <groupId ...

  10. 如果重新设计网络,有没有可能合并IP地址跟MAC地址?

    前阵子看网络基础相关的书籍,冒过一个疑问,为什么要有MAC地址跟IP地址?两者可否合二为一?   现在的逻辑是这样子:在数据传输过程中,路由器查看这个数据包的IP地址,跟路由表中记录的“IP集合:下一 ...