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> ; <root level= "Warn" > <appender-ref ref= "console"/> <!--<appender-ref ref= "file"/>--> ; </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