wildfly 16, log4j 2.17.0, NoSuchFieldError: EMPTY_BYTE_ARRAY

wildfly 16, log4j 2.17.0, NoSuchFieldError: EMPTY_BYTE_ARRAY

我在 wildfly 启动期间收到错误消息:

NoSuchFieldError: EMPTY_BYTE_ARRAY

消息还说这个错误发生在undertow部署中。谁能告诉我这里发生了什么以及如何解决这个问题?

下面是堆栈跟踪的开头。

at org.wildfly.extension.undertow@24.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:90)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:829)
at org.jboss.threads@2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)

原因:java.lang.NoSuchFieldError:EMPTY_BYTE_ARRAY 在 deployment.taggable-server.war//org.apache.logging.log4j.core.config.ConfigurationSource.(ConfigurationSource.java:56) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.config.NullConfiguration.(NullConfiguration.java:32) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.LoggerContext.(LoggerContext.java:85) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150) 在 deployment.taggable-server.war//org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47) 在 org.apache.logging.log4j.api@2.14.1//org.apache.logging.log4j.LogManager.getContext(LogManager.java:196) 在 org.apache.logging.log4j.api@2.14.1//org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)

您需要 exclude the API module 从您的部署中。您的另一个选择是使用 WildFly 26,其中包括 API.

的 2.16 版本

我遇到了同样的问题,你可以这样解决:

  1. 对于一个war:

    src/main/webapp/WEB-INF/ 内有一个 jboss-deployment-structure.xml,像这样:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
      <deployment>
         <exclusions>
            <module name="org.apache.logging.log4j.api"/>
        </exclusions>
      </deployment>
    </jboss-deployment-structure>
    
  2. 对于 ear:

    src/main/application/META-INF/ 内有一个 jboss-deployment-structure.xml 像这样:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
      <sub-deployment name="mywar.war">
         <exclusions>
            <module name="org.apache.logging.log4j.api"/>
        </exclusions>
      </sub-deployment>
    </jboss-deployment-structure>
    

将 log4j 和 log4j-api 更新到 2.16.0 版本。

如果您使用的是 spring-boot 所以,请在 pom.xml

中添加标签
 <properties> 
    <log4j2-version>2.16.0</log4j2-version>
  </properties>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.16.0</version>
        </dependency>

在pom.xml