Results 1 to 1 of 1

Thread: Log4j being loaded by Spring's TomcatInstrumentableClassLoader

  1. #1
    Join Date
    Aug 2006
    Posts
    143

    Question Log4j being loaded by Spring's TomcatInstrumentableClassLoader

    I am puzzled. I have been using log4j and Spring successfully for a long time, with log4j setup and configured at the server level by placing log4j.jar and log4j.xml under Tomcat's lib folder. That way the applications don't need their own individual log4j configuration other than instantiating a Logger in the classes.

    But when I created a custom filter mypackage.MyFilter that extends org.apache.log4j.spi.Filter, placed it in a jar in the same location as log4j.jar and log4j.xml, and used it for an appender... I get the following error at server startup:
    Code:
    log4j:ERROR A "myPackage.MyFilter" object is not assignable to a "org.apache.log4j.spi.Filter" variable.
    log4j:ERROR The class "org.apache.log4j.spi.Filter" was loaded by 
    log4j:ERROR [org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
    WebappClassLoader
      delegate: false
      repositories:
        /WEB-INF/classes/
    ----------> Parent Classloader:
    org.apache.catalina.loader.StandardClassLoader@119cca4
    ] whereas object of type 
    log4j:ERROR "myPackage.MyFilter" was loaded by [org.apache.catalina.loader.StandardClassLoader@119cca4].
    Obviously log4j is getting loaded by Spring's TomcatInstrumentableClassLoader instead of Tomcat's StandardClassLoader. Strange, but no problem so long as things worked. The Spring classloader was defined on Tomcat's conf/context.xml as the loaderClass, in order to enable Spring JPA support. It makes no mention to log4j.

    The question now is... how do I make MyFilter be loaded by the same ClassLoader so that things behave as they are supposed to?

    On a hunch, I tried cheating and putting MyFilter in the org.apache.log4j.spi package... but no luck.
    Last edited by bmelloni; Jan 19th, 2010 at 09:39 AM. Reason: Further info.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •