Java 奇怪的 jboss 控制台错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2536578/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 09:01:29  来源:igfitidea点击:

Strange jboss console error

javamavenjbosslog4jclassloader

提问by ant

I'm creating additional module to already multi-module maven project. And for this one I want everything to be like in other modules(meaning dependencies) just to test hello world, then I'll go do some more complex stuff. And it does print hello world as it should when deployed onto jboss server, but I get some strange error on console, had anyone had similar experience? and how can I fix it? Here it is :

我正在为已经多模块的 maven 项目创建附加模块。对于这个,我希望一切都像其他模块(意味着依赖项)一样,只是为了测试 hello world,然后我会去做一些更复杂的事情。当部署到 jboss 服务器时,它确实打印了 hello world,但是我在控制台上遇到了一些奇怪的错误,有没有人有过类似的经历?我该如何解决?这里是 :

15:48:35,789 ERROR [STDERR] log4j:ERROR A "org.jboss.logging.appender.FileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
15:48:35,789 ERROR [STDERR] log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
15:48:35,790 ERROR [STDERR] log4j:ERROR [BaseClassLoader@9a8d9b{vfszip:/C:/jboss-5.1.0.GA/server/default/deploy/new-module-0.0.1-SNAPSHOT.war/}] whereas object of type 
15:48:35,790 ERROR [STDERR] log4j:ERROR "org.jboss.logging.appender.FileAppender" was loaded by [org.jboss.bootstrap.NoAnnotationURLClassLoader@506411].
15:48:35,790 ERROR [STDERR] log4j:ERROR Could not instantiate appender named "FILE".

Here is the part of Appender xml

这是 Appender xml 的部分

http://pastebin.com/X7Dgdrki

http://pastebin.com/X7Dgdrki

采纳答案by Péter T?r?k

First check your <server>/conf/jboss-log4j.xmlfor the configuration of the appender named FILE(and post it here if you can - that may give us more clues).

首先检查您<server>/conf/jboss-log4j.xml的名为 appender 的配置FILE(如果可以,请在此处发布 - 这可能会给我们更多线索)。

Further investigation reveals that org.jboss.logging.appender.FileAppenderactually implements the interface org.apache.log4j.Appender. So this is apparently a classloader conflict. The same class definition (in this case org.apache.log4j.Appender), when loaded by two different classloaders, counts as two distinct classes for the JVM.

进一步调查显示,org.jboss.logging.appender.FileAppender实际实现了接口org.apache.log4j.Appender。所以这显然是一个类加载器冲突。相同的类定义(在本例中org.apache.log4j.Appender),当由两个不同的类加载器加载时,对于 JVM 算作两个不同的类。

Is log4j.jar included in your war, or in your server/lib directory? If so, you could try removing it and see whether it resolves the issue.

log4j.jar 是包含在您的战争中还是包含在您的 server/lib 目录中?如果是这样,您可以尝试删除它并查看它是否可以解决问题。

Update:Actually the easiest possible solution is to simply change the type of the appender to org.apache.log4j.FileAppenderin jboss-log4j.xml.

更新:实际上最简单的解决方案是简单地将 appender 的类型更改为org.apache.log4j.FileAppenderjboss-log4j.xml。

Regarding log4j.jar, what I mean is that if it is present in your war, it (and a copy of org.apache.log4j.Appender) gets loaded by the war classloader (BaseClassLoader@9a8d9bin your error message). And this causes the classloader conflict. So if you do not deploy log4j.jar with your war, the error may go away. This is related to Maven only in that the dependency is configured in your pom. For this little experiment, you can simply remove the log4j.jar from your war by hand; if this solves the issue, configure the log4j dependency in your pom as "provided", e.g.:

关于 log4j.jar,我的意思是,如果它存在于您的战争中,它(以及 的副本org.apache.log4j.Appender)将被战争类加载器(BaseClassLoader@9a8d9b在您的错误消息中)加载。这会导致类加载器冲突。所以如果你没有在你的战争中部署 log4j.jar,错误可能会消失。这仅与 Maven 相关,因为在您的 pom 中配置了依赖项。对于这个小实验,您可以简单地手动从战争中删除 log4j.jar;如果这解决了问题,请将 pom 中的 log4j 依赖项配置为“提供”,例如:

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.12</version>
        <scope>provided</scope>
    </dependency>

If log4j.jar is not in your war, it might still be in the server/default/lib directory - please check that and if it is there, try to remove it.

如果 log4j.jar 不在您的战争中,它可能仍在 server/default/lib 目录中 - 请检查它,如果它在那里,请尝试将其删除。

回答by Mr. Mundkowsky

We recently came across this problem. We tried the suggestions above and they did not work. So we handled the problem by replacing all log4j imports with a abstract logging interface (we chose org.apache.commons.logging for this) and removing the log4j from the depdenancies. Then what happens is the actual underlying logging implementation supports whatever JBoss has set. And if we want to move back to Tomcat (without JBoss) we can just add the log4j jar or whatever logger implementation back into the war.

我们最近遇到了这个问题。我们尝试了上述建议,但没有奏效。因此,我们通过用抽象日志记录接口替换所有 log4j 导入(我们为此选择 org.apache.commons.logging)并从依赖项中删除 log4j 来处理该问题。然后发生的是实际的底层日志实现支持 JBoss 设置的任何内容。如果我们想回到 Tomcat(没有 JBoss),我们只需将 log4j jar 或任何记录器实现重新添加到战争中。