趁今天有时间整理了一下

启动命令为

//开发环境

java -jar app.jar --spring.profiles.active=dev--server.port=8060

//测试环境

java -jar app.jar --spring.profiles.active=qa --server.port=8060

//生产环境

java -jar app.jar --spring.profiles.active=prod --server.port=8060

废话少说,直接上代码

application.yml,打包为jar的时候主要把spring.profile.active注释掉.否则 命令行参数 --spring.profiles.active可能不生效,不知何解

spring:
profiles:
#指定读取配置文件:dev(开发环境),prod(生产环境),qa(测试环境)
active: qa

日志

logging:

config: classpath:logback-${spring.profiles.active}.xml

logback-dev.xml

<?xml version="1.0" encoding="UTF-8"?>

<configuration debug="true">

<contextName>logback</contextName>

<property name="log.path" value="lzw/logback.log" />
<span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="console"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.ConsoleAppender"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">filter </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.classic.filter.ThresholdFilter"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span>debug<span style="color: #0000ff">&lt;/</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">filter</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br> <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="file"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.RollingFileAppender"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span>${log.path}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">rollingPolicy </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span>${log.path}.%d{yyyy-MM-dd}.zip<span style="color: #0000ff">&lt;/</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">rollingPolicy</span><span style="color: #0000ff">&gt;</span></br></br> <span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%date %level [%thread] %logger{36} [%file : %line] %msg%n
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br></br> <span style="color: #0000ff">&lt;</span><span style="color: #800000">root </span><span style="color: #ff0000">level</span><span style="color: #0000ff">="warn"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">appender-ref </span><span style="color: #ff0000">ref</span><span style="color: #0000ff">="console"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #008000">&lt;!--</span><span style="color: #008000">&lt;appender-ref ref="file" /&gt;</span><span style="color: #008000">--&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">root</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework.scheduling"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.catalina.util.LifecycleBase"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.coyote.http11.Http11NioProtocol"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.tomcat.util.net.NioSelectorPool"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="debug"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="com.lzw"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="debug"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.mybatis"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="debug"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Connection"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Statement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.PreparedStatement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.ResultSet"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>

</configuration>

logback-qa.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration debug="true">
<contextName>logback</contextName>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">property </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="log.path"</span><span style="color: #ff0000"> value</span><span style="color: #0000ff">="lzw/logback.log"</span> <span style="color: #0000ff">/&gt;</span></br></br>

<span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="console"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.ConsoleAppender"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">filter </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.classic.filter.ThresholdFilter"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span>debug<span style="color: #0000ff">&lt;/</span><span style="color: #800000">level</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">filter</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br></br> <span style="color: #0000ff">&lt;</span><span style="color: #800000">appender </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="file"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.RollingFileAppender"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span>${log.path}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">file</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">rollingPolicy </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span>${log.path}.%d{yyyy-MM-dd}.zip<span style="color: #0000ff">&lt;/</span><span style="color: #800000">fileNamePattern</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">rollingPolicy</span><span style="color: #0000ff">&gt;</span></br></br> <span style="color: #0000ff">&lt;</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">%date %level [%thread] %logger{36} [%file : %line] %msg%n
</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">pattern</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoder</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">appender</span><span style="color: #0000ff">&gt;</span></br></br> <span style="color: #0000ff">&lt;</span><span style="color: #800000">root </span><span style="color: #ff0000">level</span><span style="color: #0000ff">="warn"</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">appender-ref </span><span style="color: #ff0000">ref</span><span style="color: #0000ff">="file"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">root</span><span style="color: #0000ff">&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework.scheduling"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="com.lzw"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.catalina.util.LifecycleBase"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.coyote.http11.Http11NioProtocol"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.apache.tomcat.util.net.NioSelectorPool"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">Logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.springframework"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="org.mybatis"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="warn"</span> <span style="color: #0000ff">/&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Connection"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.Statement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.PreparedStatement"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">logger </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="java.sql.ResultSet"</span><span style="color: #ff0000"> level</span><span style="color: #0000ff">="error"</span> <span style="color: #0000ff">/&gt;</span></br>

</configuration>

SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active(转)的更多相关文章

  1. SpringBoot application.yml logback.xml,多环境配置,支持 java -jar --spring.profiles.active

    趁今天有时间整理了一下 启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 jav ...

  2. SpringBoot application.yml logback.xml 多环境

    启动命令为 //开发环境 java -jar app.jar --spring.profiles.active=dev--server.port=8060 //测试环境 java -jar app.j ...

  3. SpringBoot在启动时的多环境配置以及加载顺序

    通常我们在开发完成一个SpringBoot项目时,总是要打包部署的. 在启动SpringBoot应用时,我们常常会使用命令java -jar xxx.jar来启动这个服务. 命令java -jar 除 ...

  4. SpringBoot | 第五章:多环境配置

    前言 写上一篇看英文资料,耗费了心力呀,这章,相对来说简单点.也比较熟悉,但是这很实用.不扯了,开始~ 多环境配置 maven的多环境配置 springboot多环境配置 总结 老生常谈 多环境配置 ...

  5. 51. spring boot属性文件之多环境配置【从零开始学Spring Boot】

    原本这个章节是要介绍<log4j多环境不同日志级别的控制的>但是没有这篇文章做基础的话,学习起来还是有点难度的,所以我们先一起了解下spring boot属性文件之多环境配置,当然文章中也 ...

  6. spring程序打包war,直接通过-jar启动,并指定spring.profiles.active参数控制多环境配置

    备注:spring boot有内嵌tomcat,jar项目可以用java -jar命令启动,war包也可以,且可以直接指定spring.profiles.active参数控制多环境配置 直接指定传参, ...

  7. 使用 spring.profiles.active 及 @profile 注解 动态化配置内部及外部配置

    引言:使用 spring.profiles.active 参数,搭配@Profile注解,可以实现不同环境下(开发.测试.生产)配置参数的切换 一.根据springboot的配置文件命名约定,结合ac ...

  8. spring boot 入门 使用spring.profiles.active来分区配置

    很多时候,我们项目在开发环境和生成环境的环境配置是不一样的,例如,数据库配置,在开发的时候,我们一般用测试数据库,而在生产环境的时候,我们是用正式的数据,这时候,我们可以利用profile在不同的环境 ...

  9. spring boot 入门 使用spring.profiles.active来分区配置(转)

    很多时候,我们项目在开发环境和生成环境的环境配置是不一样的,例如,数据库配置,在开发的时候,我们一般用测试数据库,而在生产环境的时候,我们是用正式的数据,这时候,我们可以利用profile在不同的环境 ...

随机推荐

  1. vim-normal多行操作命令的使用

    命令行命令-<:normal>这个命令可以重复上一个操作.他其实就跟.命令的效果查不到.不同的是,他可以把.的效果,作用于你用可视模式下的多行.例如,如果你想在下面的文字里在每一行加一个; ...

  2. POJ 2039 Floyd

    句意理解题 解释输入好啦: 第一行n个数 m场电影 随后m行 每行的第一个数 代表 有k奶牛在这个电影中出现过 随后k个数 是奶牛的编号 如果两头奶牛在同一个电影中出现过 相互度为1 奶牛们的相互度可 ...

  3. CDH版本大数据集群下搭建Avro(hadoop-2.6.0-cdh5.5.4.gz + avro-1.7.6-cdh5.5.4.tar.gz的搭建)

    下载地址 http://archive.cloudera.com/cdh5/cdh/5/avro-1.7.6-cdh5.5.4.tar.gz

  4. 配置Lotus Domino集群视频详解

    IBM Lotus Domino Server 有个最重要的高可用特新就是集群,它对于任何使用 Domino 服务器的组织,让用户能够持续访问它们的数据库,保证业务不间断运行.下面通过两个视频来学习如 ...

  5. 玲珑学院 1050 - array

    1050 - array Time Limit:3s Memory Limit:64MByte Submissions:494Solved:155 DESCRIPTION 2 array is an ...

  6. js14--原型2

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  7. HASH Partitioning--转载

    原文地址:https://dev.mysql.com/doc/refman/5.1/en/partitioning-hash.html HASH Partitioning [+/-] 18.2.3.1 ...

  8. 至顶网推荐-Rpm另类用法加固Linux安全

    http://www.zdnet.com.cn/ 650) this.width=650;" onclick='window.open("http://blog.51cto.com ...

  9. Atcoder At Beginner Contest 068 D - Decrease (Contestant ver.)

    D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...

  10. 【arc062e】Building Cubes with AtCoDeer

    Description STL有n块瓷砖,编号从1到n,并且将这个编号写在瓷砖的正中央: 瓷砖的四个角上分别有四种颜色(可能相等可能不相等),并且用Ci,0,Ci,1,Ci,2,Ci,3分别表示左上. ...