ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java-调试日志记录在Spring Boot 2.0.3中导致StackOverflowError

2019-11-08 18:00:39  阅读:429  来源: 互联网

标签:spring-boot java


我最近将Spring Boot应用程序从1.5.10升级到了2.0.3,现在正面临这个问题:当我将logging.level.root = DEBUG添加到application.properties时,出现以下异常:

log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "background-preinit" java.lang.StackOverflowError
  at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
  at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:293)
  at java.util.logging.Logger.log(Logger.java:738)
  at java.util.logging.Logger.doLog(Logger.java:765)
  at java.util.logging.Logger.logp(Logger.java:931)
  at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180)
  at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:103)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1154)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
  at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
  at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:293)
  at java.util.logging.Logger.log(Logger.java:738)
  at java.util.logging.Logger.doLog(Logger.java:765)
  at java.util.logging.Logger.logp(Logger.java:931)
  at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180)
  at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:103)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1154)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
  at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
  at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:293)
  ...

这只是一小部分,因为这组堆栈跟踪重复了100次以上,从而导致StackOverflowError.

我尝试过的调试步骤:

>如果将日志记录级别更改为其他任何信息(例如INFO),都不会出现异常.
>我在pom.xml中添加了SLF4JBridgeHandler的特定依赖项.
>我确保SLF4JBridgeHandler在我的Web应用程序的类路径中.

是什么导致此问题?

解决方法:

我只引用official slf4j documentation

jul-to-slf4j.jar and slf4j-jdk14.jar cannot be present simultaneously

The presence of slf4j-jdk14.jar, that is the jul binding for
SLF4J, will force SLF4J calls to be delegated to jul. On the
other hand, the presence of jul-to-slf4j.jar, plus the installation
of SLF4JBridgeHandler, by invoking “SLF4JBridgeHandler.install()
will route jul records to SLF4J. Thus, if both jar are present
simultaneously (and SLF4JBridgeHandler is installed), slf4j calls
will be delegated to jul and jul records will be routed to
SLF4J, resulting in an endless loop.

您的情况正在发生什么.

尝试执行mvndependency:tree并排除冲突的依赖项.

在我看来,spring-boot擅长管理此类依赖项.因此,通过减少手动添加的依赖项来保持pom.xml的干净非常好.

标签:spring-boot,java
来源: https://codeday.me/bug/20191108/2009788.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有