本文介绍了使用自定义类加载器配置org.apache.log4j.ConsoleAppender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java类,它在启动时基于javassist类加载器创建一个自定义类加载器,然后运行真正的程序类。
我收到以下错误:

I have a java class which creates a custom classloader based on javassist class loader on start up and then run the real program class.I'm getting the following error:

log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a        
"org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by 
log4j:ERROR [javassist.Loader@6f97b10a] whereas object of type 
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by 
[java.net.URLClassLoader@5b414a8d].
log4j:ERROR Could not instantiate appender named "stdout".

问题与原始类加载器创建一个对象而另一个对象创建的事实有关自定义的。

有没有办法解决这个错误?

The problem is related to the fact that one object is created by the original classloader while the other is created by the custom one.
Is there a way to resolve this error?

提前致谢,
Avner

Thanks in advance,
Avner

推荐答案

请尝试设置-Dlog4j.ignoreTCL = true,希望它有所帮助。类似的问题

Please try to set -Dlog4j.ignoreTCL=true, hope it helps. a simular issue about log4j

这篇关于使用自定义类加载器配置org.apache.log4j.ConsoleAppender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:45