Springboot application.yml logback.xml, Multi-environment configuration, support Java-jar--spring.profiles.active

Source: Internet
Author: User

Let's have some time to tidy up today.

The Start command is

Development environment

Java-jar App.jar--spring.profiles.active=dev--server.port=8060

Test environment

Java-jar App.jar--spring.profiles.active=qa--server.port=8060

Production environment

Java-jar App.jar--spring.profiles.active=prod--server.port=8060

Talk less, directly on the code

APPLICATION.YML, when packaged as a jar, spring.profile.active the main comment. Otherwise, the command-line parameter--spring.profiles.active may not take effect, do not know how to solve

Spring:  Profiles:    #指定读取配置文件:d EV (development environment), PROD (production environment), QA (test environment)    active:qa# log 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"/> <appender name= "console" class= "Ch.qos            . Logback.core.ConsoleAppender "> <filter class=" Ch.qos.logback.classic.filter.ThresholdFilter "> <level>debug</level> </filter> <encoder> <pattern>%d{hh:mm:ss. SSS}%contextname [%thread]%-5level%logger{36}-%msg%n </pattern> </encoder> </appe nder> <appender name= "file" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <file>${log. path}</file> <rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > < Filenamepattern>${log.path}.%d{yyyy-mm-dd}.zip</filenamepattern> </rollingPolicy> <encoder > <pattern>%date%Level [%thread]%logger{36} [%file:%line]%msg%n </pattern> </encoder> </appender&gt    ; <root level= "Warn" > <appender-ref ref= "console"/> <!--<appender-ref ref= "file"/>--&gt    ; </root> <logger name= "org.springframework.scheduling" level= "error"/> <logger name= "Org.apache.cata Lina.util.LifecycleBase "level=" error "/> <logger name=" Org.apache.coyote.http11.Http11NioProtocol "level=" Warn "/> <logger name=" Org.apache.tomcat.util.net.NioSelectorPool "level=" Warn "/> <logger name=" Org.spr Ingframework "level=" Debug "/> <logger name=" COM.LZW "level=" Debug "/> <logger name=" Org.mybatis "level= "Debug"/> <logger name= "java.sql" level= "error"/> <logger name= "java.sql.Connection" level= "error"/&G    T <logger name= "java.sql.Statement" level= "error"/> <logger name= "java.sql.PreparedStatement" level= "error"/ > <loggEr name= "java.sql.ResultSet" level= "error"/></configuration> 

Logback-qa.xml

<?xml version= "1.0" encoding= "UTF-8" standalone= "yes"? ><configuration debug= "true" > <contextName> logback</contextname> <property name= "Log.path" value= "Lzw/logback.log"/> <appender name= "Console" C lass= "Ch.qos.logback.core.ConsoleAppender" > <filter class= "Ch.qos.logback.classic.filter.ThresholdFilter" &            Gt <level>debug</level> </filter> <encoder> <pattern>%d{hh:mm:ss. SSS}%contextname [%thread]%-5level%logger{36}-%msg%n </pattern> </encoder> </appe nder> <appender name= "file" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <file>${log. path}</file> <rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > < Filenamepattern>${log.path}.%d{yyyy-mm-dd}.zip</filenamepattern> </rollingPolicy> <encoder > <pAttern>%date%level [%thread]%logger{36} [%file:%line]%msg%n </pattern> </encoder> </appender> <root level= "warn" > <appender-ref ref= "file"/> </root> <logger na Me= "org.springframework.scheduling" level= "error"/> <logger name= "COM.LZW" level= "warn"/> <logger nam E= "Org.apache.catalina.util.LifecycleBase" level= "Warn"/> <logger name= " Org.apache.coyote.http11.Http11NioProtocol "level=" Warn "/> <logger name=" Org.apache.tomcat.util.net.NioSelectorPool "level=" Warn "/> <logger name=" org.springframework "level=" Warn "/&    Gt <logger name= "Org.mybatis" level= "Warn"/> <logger name= "java.sql" level= "error"/> <logger name= "Jav A.sql.connection "level=" error "/> <logger name=" java.sql.Statement "level=" error "/> <logger name=" java . sql. PreparedStatement "level=" error "/> <logger name=" java.sql.ResultSet "level=" error "/></configuration> 

Springboot application.yml logback.xml, Multi-environment configuration, support Java-jar--spring.profiles.active

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.