gpt4 book ai didi

java - DEBUG 日志记录导致 Spring Boot 2.0.3.RELEASE 中的 StackOverflowError

转载 作者:搜寻专家 更新时间:2023-11-01 02:36:06 25 4
gpt4 key购买 nike

我最近将我的 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 在我的网络应用程序的类路径中。

是什么导致了这个问题?

最佳答案

我只引用 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.

这就是您的情况。


尝试执行 mvn dependency:tree 并排除冲突的依赖项。

在我看来,spring-boot 擅长管理这样的依赖关系。因此,最好保持 pom.xml 干净,减少手动添加的依赖项。

关于java - DEBUG 日志记录导致 Spring Boot 2.0.3.RELEASE 中的 StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51483775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com