运行 Log4j2 with Java 11 and Spring Boot causes NullPointerException

Running Log4j2 with Java 11 and Spring Boot causes NullPointerException

当我的 Spring 启动应用程序启动并在 Java 11 中初始化我的 Log4j2 记录器时,我得到以下异常:

2021-10-08 11:20:29,949 main INFO Cannot initialize scripting support because this JRE does not support it. java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "javax.script.ScriptEngine.get(String)" is null
at org.luaj.vm2.script.LuaScriptEngineFactory.getParameter(Unknown Source)
at org.apache.logging.log4j.core.script.ScriptManager.<init>(ScriptManager.java:84)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:219)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:287)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:627)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:700)
at org.apache.logging.log4j.core.LoggerContext.setConfigLocation(LoggerContext.java:685)

几年前同样的问题在这里有另一个答案:

然而,这个几年前的答案并没有给我所需的步骤来弄清楚如何删除它。有人讨论说这是一个 OpenJDK 问题,现在应该修复它,但我仍在为此苦苦挣扎。

有没有人更了解这个问题,为什么它只发生在 Spring 启动时,我可以做些什么来以干净的方式摆脱它?

您的问题与 . Your classpath must contain the luaj-jse 脚本引擎不同,它有一个错误:

    public Object getParameter(String key) {
        return getScriptEngine().get(key).toString();
    }

当调用 getParameter 时缺少键(如 "THREADING"),这会导致 NullPointerException.

你应该 report this bug 到 LuaJ。同时,您可以忽略错误或从依赖项中删除 luaj-jse