log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.

 

多个classloader加载log4j时需要设置当前Thread的classloader为你自己的classloader

 

Thread.currentThread().setContextClassLoader(classLoader); //for log4j

 

摘自:org.apache.log4j.helpers.Loader

  /**
   * If running under JDK 1.2 load the specified class using the
   *  <code>Thread</code> <code>contextClassLoader</code> if that
   *  fails try Class.forname. Under JDK 1.1 only Class.forName is
   *  used.
   *
   */
  static public Class loadClass (String clazz) throws ClassNotFoundException {
    // Just call Class.forName(clazz) if we are running under JDK 1.1
    // or if we are instructed to ignore the TCL.
    if(java1 || ignoreTCL) {
      return Class.forName(clazz);
    } else {
      try {
    return getTCL().loadClass(clazz);
      } catch(Throwable e) {
    // we reached here because tcl was null or because of a
    // security exception, or because clazz could not be loaded...
    // In any case we now try one more time
    return Class.forName(clazz);
      }
    }

 

log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [com.generallycloud.baseio.container.URLDynamicClassLoader@55740540] whereas object of type
log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [sun.misc.Launcher$AppClassLoader@18b4aac2].
log4j:ERROR Could not instantiate appender named "main".
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 [com.generallycloud.baseio.container.URLDynamicClassLoader@55740540] whereas object of type
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader@18b4aac2].
log4j:ERROR Could not instantiate appender named "console".
log4j:WARN No appenders could be found for logger (com.generallycloud.baseio.component.ssl.SSLUtil).
log4j:WARN Please initialize the log4j system properly.

原文:http://www.cnblogs.com/gifisan/p/6879465.html  

 

posted @ 2017-05-19 17:14  gifisan  阅读(4663)  评论(0编辑  收藏  举报