NoSuchMethodError: org.apache.logging.log4j.util.StackLocatorUtil.getCurrentStackTrace()

        最近在修复log4j的漏洞,我们的办法是把所有org.apache.logging.log4j下的依赖,都升级到2.17.0以上,看了看maven仓内的版本情况,决定全部升到2.17.2。


    org.apache.logging.log4j
    log4j-core
    2.17.2


    org.apache.logging.log4j
    log4j-slf4j-impl
    2.17.2


    org.apache.logging.log4j
    log4j-1.2-api
    2.17.2


    org.apache.logging.log4j
    log4j-api
    2.17.2

        编译后一切顺利,检查也正常,部署到测试环境接口功能也正常。但即将上线的时候,查看容器debug日志,发现如下报错。

Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.util.StackLocatorUtil.getCurrentStackTrace()Ljava/util/Deque;
    at org.apache.logging.log4j.core.impl.ThrowableProxy.(ThrowableProxy.java:112)
    at org.apache.logging.log4j.core.impl.ThrowableProxy.(ThrowableProxy.java:97)
    at org.apache.logging.log4j.core.impl.Log4jLogEvent.getThrownProxy(Log4jLogEvent.java:629)
    at org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter.format(ExtendedThrowablePatternConverter.java:63)
    at com.cmb.bee.commons.log4j2.ExtendedWhitespaceThrowablePatternConverter.format(ExtendedWhitespaceThrowablePatternConverter.java:50)
    at org.apache.logging.log4j.core.layout.PatternLayout$NoFormatPatternSerializer.toSerializable(PatternLayout.java:342)
    at org.apache.logging.log4j.core.layout.PatternLayout.toText(PatternLayout.java:240)
    at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:225)
    at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:59)
    at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:215)
    at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:208)
    at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:199)
    at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:161)

        感觉是版本依赖出现了问题,导致一个方法的返回无法识别。在网上查找资料,终于找到一段有用的描述。java - Log4J2 AppenderLoggingException NoSuchMethodError StackLocatorUtil.getCurrentStackTrace() - Stack Overflowicon-default.png?t=N7T8https://stackoverflow.com/questions/71722390/log4j2-appenderloggingexception-nosuchmethoderror-stacklocatorutil-getcurrentsta

Turns out a library had the dependency Log4J-api 2.17.1 (but not -core), my gradle file specified Log4J-core 2.17.2 so the older -api version overrid the latest one. Apparently, from 2.17.1 to .2, StackLocatorUtil.getCurrentStackTrace() now returns a Deque, previously a Stack

--个人理解是,尝试把全部版本回退至2.17.1。本地尝试后,这个错误不再存在。

目前已无报错。

你可能感兴趣的:(4.问题解决,java)