将Log4j2 2.11.1与Wildfly 14.0.1,OpenJDK 11结合使用。我们有一个自定义的OSGi客户端应用程序,该应用程序既可以记录到控制台附加程序,也可以记录到JMS附加程序,以将记录事件发送到Wildfly服务器。
在Log4j2之前,我们以编程方式将JMS附加程序粘贴到我们的Log4j配置中,效果很好。确实没有必要,因此在我们最近升级到Log4j2时,我正在尝试使用log4j2.xml配置来处理所有这些问题并简化我们的代码。
我们有一个客户端类,它使用以下命令成功连接到Wildfly JMS并接收消息:
topicConnFacName: com.rsc.mmpl.TopicConnectionFactory
initialContextFacName: org.jboss.naming.remote.client.InitialContextFactory
URL: http-remoting://JDEVDWS166:9090
Topic name: com.rsc.mmpl.MsgHndlrTopic
我的log4j2.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%p %d{yyyy-MMM-dd HH:mm:ss.SSS} %c{3}[line %L] - %m%n"/>
</Console>
<JMS name="jmsQueue" destinationBindingName="com.rsc.mmpl.MsgHndlrTopic"
factoryName="org.jboss.naming.remote.client.InitialContextFactory"
factoryBindingName="com.rsc.mmpl.TopicConnectionFactory"
ignoreExceptions="false"
providerURL="http-remoting://JDEVDWS166:9090">
<JsonLayout properties="true" complete="true"/>
</JMS>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="jmsQueue"/>
</Root>
</Loggers>
</Configuration>
如果我注释掉我的JMS Appender,它可以正常工作,所以我知道从类路径的角度正确设置了我的log4j(log4j核心和api jar以及jackson jar和jboss-client.jar都在整体类路径)。
但是,当使用JMS Appender运行客户端应用程序时,出现以下错误:
[stderr] Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jboss.remoting3.ConfigurationEndpointSupplier$Holder
[stderr] at org.jboss.remoting3.ConfigurationEndpointSupplier.get(ConfigurationEndpointSupplier.java:84)
[stderr] at org.jboss.remoting3.ConfigurationEndpointSupplier.get(ConfigurationEndpointSupplier.java:40)
[stderr] at org.wildfly.common.context.ContextManager.getPrivileged(ContextManager.java:286)
[stderr] at org.jboss.remoting3.Endpoint.getCurrent(Endpoint.java:81)
[stderr] at org.wildfly.naming.client.remote.RemoteNamingProviderFactory.getEndpoint(RemoteNamingProviderFactory.java:49)
[stderr] at org.wildfly.naming.client.remote.RemoteNamingProviderFactory.supportsUriScheme(RemoteNamingProviderFactory.java:40)
[stderr] at org.wildfly.naming.client.WildFlyRootContext.getProviderContext(WildFlyRootContext.java:784)
[stderr] at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:140)
[stderr] at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)
[stderr] at org.apache.logging.log4j.core.net.JndiManager.lookup(JndiManager.java:172)
[stderr] at org.apache.logging.log4j.core.appender.mom.JmsManager.createConnection(JmsManager.java:323)
[stderr] at org.apache.logging.log4j.core.appender.mom.JmsManager.<init>(JmsManager.java:250)
[stderr] at org.apache.logging.log4j.core.appender.mom.JmsManager.<init>(JmsManager.java:54)
[stderr] at org.apache.logging.log4j.core.appender.mom.JmsManager$JmsManagerFactory.createManager(JmsManager.java:130)
[stderr] at org.apache.logging.log4j.core.appender.mom.JmsManager$JmsManagerFactory.createManager(JmsManager.java:125)
[stderr] at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:113)
[stderr] at org.apache.logging.log4j.core.appender.mom.JmsAppender$Builder.build(JmsAppender.java:118)
[stderr] at org.apache.logging.log4j.core.appender.mom.JmsAppender$Builder.build(JmsAppender.java:50)
[stderr] at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
[stderr] at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
[stderr] at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
[stderr] at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
[stderr] at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
[stderr] at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
[stderr] at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
[stderr] at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
[stderr] at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
[stderr] at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
[stderr] at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
[stderr] at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)
[stderr] at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
[stderr] at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
[stderr] at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)
[stderr] at com.rsc.delphi.logger.log4j.Log4jLogger.<init>(Unknown Source)
[stderr] ... 20 more
看看Holder的来源,那里的静态块似乎出了点问题,但是我一辈子都无法弄清楚是什么。
有什么方法可以获取更多信息来找出此处失败的原因吗?再次,以编程方式连接到Wildfly JMS很好,这似乎与Log4j2有关。
谢谢。
答案 0 :(得分:0)
看着它,我的第一个猜测是问题不在于堆栈跟踪的顶部。该类加载问题可能源自log4j2
与WildFly
命名接口的连接。
它看起来像一个新的InitialContextFactory
(subclassed) module is now provided。这意味着您必须进行以下更改:
org.jboss.naming.remote.client.InitialContextFactory
收件人:
org.wildfly.naming.client.WildFlyInitialContextFactory