在为Log4j2添加新模块后,Wildfly日志在启动时爆发了几个ClassNotFoundException。看起来它正在寻找其他Java EE类的模块,我新定义的模块与之无关。
以下是其中一个例外:
17:52:57,865 WARN [org.jboss.modules] (ServerService Thread Pool -- 52) Failed to define class org.apache.logging.log4j.core.net.AbstractJMSReceiver in Module "org.apache.log4j2:main" from local module loader @1c323a (finder: local module finder @125871f (roots: /usr/local/share/wildfly/modules,/usr/local/share/wildfly/modules/system/layers/base)): java.lang.LinkageError: Failed to link org/apache/logging/log4j/core/net/AbstractJMSReceiver (Module "org.apache.log4j2:main" from local module loader @1c323a (finder: local module finder @125871f (roots: /usr/local/share/wildfly/modules,/usr/local/share/wildfly/modules/system/layers/base)))
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:428) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.Module.loadModuleClass(Module.java:548) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:189) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final]
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_67]
at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_67]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:345) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:423) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.Module.loadModuleClass(Module.java:548) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:189) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final]
at org.apache.logging.log4j.core.config.plugins.ResolverUtil.addIfMatching(ResolverUtil.java:436) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.config.plugins.ResolverUtil.loadImplementationsInJar(ResolverUtil.java:411) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.config.plugins.ResolverUtil.loadImplementationsInJar(ResolverUtil.java:367) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.config.plugins.ResolverUtil.findInPackage(ResolverUtil.java:264) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:174) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:130) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.config.BaseConfiguration.start(BaseConfiguration.java:152) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:341) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:386) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:149) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:84) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:35) [log4j-core-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:444) [log4j-api-2.0-rc1.jar:2.0-rc1]
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:389) [log4j-api-2.0-rc1.jar:2.0-rc1]
at com.extraliga.domain.ExtraligaEntity.<init>(Unknown Source) [extraliga-persistence.jar:]
at com.extraliga.domain.util.EmailConverter.<init>(Unknown Source) [extraliga-persistence.jar:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_67]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_67]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_67]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_67]
at java.lang.Class.newInstance(Class.java:374) [rt.jar:1.7.0_67]
at org.hibernate.cfg.annotations.reflection.XMLContext.setLocalAttributeConverterDefinitions(XMLContext.java:206) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.annotations.reflection.XMLContext.addDocument(XMLContext.java:113) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:528) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:517) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:512) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.Configuration.add(Configuration.java:686) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:724) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1163) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:846) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.1.Final.jar:4.3.1.Final]
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_67]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474) [wildfly-security-manager-1.0.0.Final.jar:1.0.0.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.0.0.Final.jar:8.0.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_67]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]
at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
Caused by: java.lang.NoClassDefFoundError: javax/jms/MessageListener
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_67]
at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_67]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:345) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:423) [jboss-modules.jar:1.3.0.Final]
... 63 more
Caused by: java.lang.ClassNotFoundException: javax.jms.MessageListener from [Module "org.apache.log4j2:main" from local module loader @1c323a (finder: local module finder @125871f (roots: /usr/local/share/wildfly/modules,/usr/local/share/wildfly/modules/system/layers/base))]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final]
... 67 more
目前我只是尝试部署我的持久性单元存档,以确保我已正确映射所有内容,此存档依赖于Log4j2。在我的持久性存档的META-INF目录中,我有一个jboss-deployment-structure.xml,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j"/>
</exclusions>
<dependencies>
<module name="org.apache.log4j2">
<imports>
<include path="META-INF"/>
</imports>
</module>
</dependencies>
</deployment>
</jboss-deployment-structure>
我的模块由Wildfly中的以下目录结构定义:
$WILDFLY_HOME/modules/org/apache/log4j2/main/
log4j-api-2.0-rc1.jar
log4j-core-2.0-rc1.jar
module.xml
最后我的module.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.log4j2">
<resources>
<resource-root path="log4j-api-2.0-rc1.jar"/>
<resource-root path="log4j-core-2.0-rc1.jar"/>
</resources>
<dependencies>
<module name="com.lmax.disruptor"/>
<module name="javax.api"/>
<module name="javax.servlet.api"/>
</dependencies>
</module>
看起来很奇怪wildfly甚至会在这一点上试图寻找javax.jms.MessageListener,甚至更多的是它正在寻找它“来自org.apache.log4j2:main”
有没有人知道如何解决此异常?
答案 0 :(得分:2)
WildFly并未尝试查找javax.jms.MessageListener
org.apache.logging.log4j.core.net.AbstractJMSReceiver
。我不知道log4j2有多少其他依赖项,但您至少需要添加javax.jmx
作为依赖项。