DEBUG Logging Causes StackOverflowError in Spring Boot 2.0.3.RELEASE

nicholas79171 :

I recently upgraded my Spring Boot app from 1.5.10 to 2.0.3 and am now facing this issue: when I add logging.level.root=DEBUG to my application.properties, I get the following exception:

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)
  ...

This is only a small portion, as this set of the stack trace repeats over 100 times, causing the StackOverflowError.

Debugging steps I've tried:

  • If I change the logging level to anything else, like INFO, I don't get the exception.
  • I've added a specific dependency for SLF4JBridgeHandler in my pom.xml.
  • I've made sure that SLF4JBridgeHandler is on the classpath of my web app.

What could be causing this issue?

Raja Anbazhagan :

I'll just quote the 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.

Which is what is happening to your case.


Try doing mvn dependency:tree and exclude the conflicting dependencies.

In my opinion, spring-boot is good at managing dependencies like this. So its good to keep the pom.xml clean with less manually added dependencies.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=77930&siteId=1