SpringBoot项目的一些简单常用配置
2021-05-01 19:29
标签:lsp edr roo policy hub 存在 json 属性 core SpringBoot项目的相关配置在application.properties文件中进行配置: web项目常用的配置: 日志配置: 日志常用配置项 默认值 备注 logging.file 日志输出的文件地址 logging.level.ROOT info 设置日志的输出级别 logging.level.* info 定义指定包的输出级别 logging.config logback-spring.xml 日志的配置文件 注意:SpringBoot默认并没有进行文件输出,只在控制台中进行了打印。 日志级别:debug>info>warn>error,默认情况下springboot日志级别为info 如果设置了debug=true时,日志会降级为debug SpringBoot的日志可以支持logback框架,只需要在resources目录下写一个模板的文件即可,使用了其他日志框架后,就不需要再application.properties文件中配置日志项了。 logback模板:(来自鲁班学院-荆轲老师分享) yml配置: SpringBoot支持两种格式的配置文件 属性文件:application.properties yml:application.yml yml是一种简介的非标记语言。yml以数据为中心,使用空白,缩进,分行组织数据,从而使得表示更加简洁易读。 yml语法格式: 标准格式:key:(空格)value 使用空格代表层级关系,以“:”结束 yml和properties同时都存在时,以properties为主。 Banner配置: Banner是指SpringBoot启动时显示的字符画,默认是“spring”。我们可以新建resources/banner.txt进行修改。
关闭Banner显示: SpringBoot项目的一些简单常用配置 标签:lsp edr roo policy hub 存在 json 属性 core 原文地址:https://www.cnblogs.com/wk-missQ1/p/13205547.html#自己设置端口号
server.port=8090
#启用debug模式(默认的日志级别是debug)
#debug=true
#上下文配置,默认是/
server.servlet.context-path=/wk
#字符编码配置,默认是UTF-8
server.servlet.encoding.charset=utf-8
#关闭缓存(开发测试阶段建议关闭)
spring.thymeleaf.cache=false
#设置日期格式(web传值过程中有效)
spring.mvc.format.date=yyyy-MM-dd
#设置日期格式(json解析过程中有效)
spring.jackson.date-format=yyyy-MM-dd
#设置时区
spring.jackson.time-zone=GMT+8
#配置日志输出的路径
#logging.file.path=/logs
logging.file.name=d:/logs/log02.log
#设置日志级别,常用的四种级别debug-info-warn-error
#在设置自己的日志级别时,需要把启用的debug模式关闭
#可以把root设置成具体的包名如:logging.level.com.wk.demo3 = info
logging.level.root = info
xml version="1.0" encoding="UTF-8"?>
configuration debug="false">
property name="PROJECT" value="mysb1" />
property name="ROOT" value="d:/logs/${PROJECT}/" />
property name="FILESIZE" value="50MB" />
property name="MAXHISTORY" value="100" />
timestamp key="DATETIME" datePattern="yyyy-MM-dd HH:mm:ss" />
appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
encoder charset="utf-8">
pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
pattern>
encoder>
appender>
appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
encoder charset="utf-8">
pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
pattern>
encoder>
filter class="ch.qos.logback.classic.filter.LevelFilter">
level>ERRORlevel>
onMatch>ACCEPTonMatch>
onMismatch>DENYonMismatch>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
fileNamePattern>${ROOT}%d/error.%i.logfileNamePattern>
maxHistory>${MAXHISTORY}maxHistory>
timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
maxFileSize>${FILESIZE}maxFileSize>
timeBasedFileNamingAndTriggeringPolicy>
rollingPolicy>
appender>
appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
encoder charset="utf-8">
pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
pattern>
encoder>
filter class="ch.qos.logback.classic.filter.LevelFilter">
level>WARNlevel>
onMatch>ACCEPTonMatch>
onMismatch>DENYonMismatch>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
fileNamePattern>${ROOT}%d/warn.%i.logfileNamePattern>
maxHistory>${MAXHISTORY}maxHistory>
timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
maxFileSize>${FILESIZE}maxFileSize>
timeBasedFileNamingAndTriggeringPolicy>
rollingPolicy>
appender>
appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
encoder charset="utf-8">
pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
pattern>
encoder>
filter class="ch.qos.logback.classic.filter.LevelFilter">
level>INFOlevel>
onMatch>ACCEPTonMatch>
onMismatch>DENYonMismatch>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
fileNamePattern>${ROOT}%d/info.%i.logfileNamePattern>
maxHistory>${MAXHISTORY}maxHistory>
timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
maxFileSize>${FILESIZE}maxFileSize>
timeBasedFileNamingAndTriggeringPolicy>
rollingPolicy>
appender>
appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
encoder charset="utf-8">
pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
pattern>
encoder>
filter class="ch.qos.logback.classic.filter.LevelFilter">
level>DEBUGlevel>
onMatch>ACCEPTonMatch>
onMismatch>DENYonMismatch>
filter>
rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
fileNamePattern>${ROOT}%d/debug.%i.logfileNamePattern>
maxHistory>${MAXHISTORY}maxHistory>
timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
maxFileSize>${FILESIZE}maxFileSize>
timeBasedFileNamingAndTriggeringPolicy>
rollingPolicy>
appender>
appender name="TRACE" class="ch.qos.logback.core.rolling.RollingFileAppender">
encoder charset="utf-8">
pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
pattern>
encoder>
filter class="ch.qos.logback.classic.filter.LevelFilter">
level>TRACElevel>
onMatch>ACCEPTonMatch>
onMismatch>DENYonMismatch>
filter>
rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
fileNamePattern>${ROOT}%d/trace.%i.logfileNamePattern>
maxHistory>${MAXHISTORY}maxHistory>
timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
maxFileSize>${FILESIZE}maxFileSize>
timeBasedFileNamingAndTriggeringPolicy>
rollingPolicy>
appender>
logger name="org.apache.ibatis" level="INFO" additivity="false" />
logger name="org.mybatis.spring" level="INFO" additivity="false" />
logger name="com.github.miemiedev.mybatis.paginator" level="INFO" additivity="false" />
root level="DEBUG">
appender-ref ref="STDOUT" />
appender-ref ref="DEBUG" />
appender-ref ref="ERROR" />
appender-ref ref="WARN" />
appender-ref ref="INFO" />
appender-ref ref="TRACE" />
root>
configuration>
server:
port: 80
servlet:
context-path: /yoyo
spring:
banner:
charset: utf-8
thymeleaf:
cache: false
mvc:
format:
date: yyyy-MM-dd
jackson:
date-format: yyyy-MM-dd
time-zone: GMT+8
SpringApplication app = new SpringApplication(Springbootdemo200Application.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
文章标题:SpringBoot项目的一些简单常用配置
文章链接:http://soscw.com/index.php/essay/81008.html