Spring Boot 启动卡住了
Spring Boot 疑难问题,启动卡住,没有日志,很难排查
·
spring boot 项目,启动时,一直卡在这里,不动了,经过艰苦排查,原因如下:
原因:
application.yml 中没有配置log路径。
server:
port: 8081
spring:
application:
name: loveday-gather
logging:
file:
path: ../db/logs
将下面log路径配置,加上,问题解决
logging:
file:
path: ../db/logs
编外:
也有可能是logback-spring.xml 配置问题,导致控制台的日志没有被打印。如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:[项目名] %d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<!-- <pattern>[loveday-gather] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) [%X{traceId}] %cyan(%logger{50}) - %highlight(%msg) %n</pattern>-->
<pattern>[loveday-gather] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{traceId}] %logger{50} - %msg %n</pattern>
</encoder>
</appender>
.......
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="INFO">
....
</root>
</configuration>
在:<root></root> 内,没有 <appender-ref ref="console"/>, 也同样不打印日志。
附录:logback-spring.xml 完整内容
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:[项目名] %d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<!-- <pattern>[loveday-gather] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) [%X{traceId}] %cyan(%logger{50}) - %highlight(%msg) %n</pattern>-->
<pattern>[loveday-gather] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{traceId}] %logger{50} - %msg %n</pattern>
</encoder>
</appender>
<!-- Log file debug output -->
<appender name="stdout" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/stdout.out</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM}/stdout.%d{yyyy-MM-dd}.%i.out</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>[loveday-gather] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{traceId}] %logger{50} - %msg %n</pattern>
</encoder>
</appender>
<!-- Log ferrorsrror output -->
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>[loveday-gather] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{traceId}] %logger{50} - %msg %n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
<logger name="com.alibaba.nacos.client" level="off" />
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="stdout"/>
<appender-ref ref="error"/>
</root>
</configuration>
更多推荐
已为社区贡献3条内容
所有评论(0)