Announcement Announcement Module
Collapse
No announcement yet.
Error configuring application listener ContextLoaderListener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error configuring application listener ContextLoaderListener

    Hi guys, newbie to Spring and so far been having a lot of fun learning the basics. However I've spent the last day or so trying to figure this one out. The strange thing is this error only occurs when I try to start Tomcat from within Eclipse, Tomcat starts ok from the command line.

    Here's the stack trace when I try to start from Eclipse. I'm using the SpringSource ToolSuite version of Eclipse and I've configured my server instance to use the Tomcat installation as the Server Location.

    INFO: Deploying web application archive online-bank.war
    13:46:44,125 ERROR [/online-bank]:3715 - Error configuring application listener of class org.springframework.web.context.ContextLoaderListe ner
    java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :620)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1277)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1208)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3712)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4216)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:760)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:740)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:544)
    at org.apache.catalina.startup.HostConfig.deployWAR(H ostConfig.java:825)
    at org.apache.catalina.startup.HostConfig.deployWARs( HostConfig.java:714)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:490)
    at org.apache.catalina.startup.HostConfig.check(HostC onfig.java:1206)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:293)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.backgroundP rocess(ContainerBase.java:1306)
    at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.processChildren(ContainerBase.ja va:1570)
    at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.processChildren(ContainerBase.ja va:1579)
    at org.apache.catalina.core.ContainerBase$ContainerBa ckgroundProcessor.run(ContainerBase.java:1559)
    at java.lang.Thread.run(Thread.java:595)
    13:46:44,125 ERROR [/online-bank]:3722 - Skipped installing application listeners due to previous error(s)
    05-Sep-2009 13:46:44 org.apache.catalina.core.StandardContext start
    SEVERE: Error listenerStart
    05-Sep-2009 13:46:44 org.apache.catalina.core.StandardContext start
    SEVERE: Context [/online-bank] startup failed due to previous errors

    I've googled the error and seen several different answers. One is that the Spring jar isn't in the WEB-INF/lib. Double checked that and it is present.

    Another solution was as in this thread -> http://forum.springsource.org/showthread.php?t=28516 where useSystemClassLoaderAsParent needs to be set to false.

    I looked up where this should be done and found it mentioned in several different docs including the Spring Reference pdf. The format given is as follows:
    Code:
    <Context path="/myWebApp" docBase="/my/webApp/location">
    <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
                useSystemClassLoaderAsParent="false"
    />
    
    </Context>
    I've set it as follows :
    Code:
    <Context path="/online-bank" docBase="online-bank">
    <Loader 
                useSystemClassLoaderAsParent="false"
    />
    </Context>
    which I put in the <Host> .. </Host> element in my server xml. The stacktrace given now contains additional errors as well as the same exception already given:

    4:27:35,812 ERROR [/online-bank]:3715 - Error configuring application listener of class org.springframework.web.context.ContextLoaderListe ner

    .....etc

    processTlds
    SEVERE: Error reading tld listeners java.lang.NullPointerException
    java.lang.NullPointerException
    at org.apache.log4j.Category.isEnabledFor(Category.ja va:746)
    at org.apache.commons.logging.impl.Log4JLogger.isTrac eEnabled(Log4JLogger.java:327)
    at org.apache.catalina.startup.TldConfig.tldScanResou rcePaths(TldConfig.java:581)
    at org.apache.catalina.startup.TldConfig.execute(TldC onfig.java:282)
    at org.apache.catalina.core.StandardContext.processTl ds(StandardContext.java:4307)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4144)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:760)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:740)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:544)
    at org.apache.catalina.startup.HostConfig.deployDescr iptor(HostConfig.java:626)
    at org.apache.catalina.startup.HostConfig.deployDescr iptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1022)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:736)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1014)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:448)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:700)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:413)
    05-Sep-2009 14:27:35 org.apache.catalina.core.StandardContext processTlds
    SEVERE: Error reading tld listeners java.lang.NullPointerException
    java.lang.NullPointerException

    ......etc

    I've left out the LoaderClass which is mentioned in the example i.e.
    Code:
    <Context path="/online-bank" docBase="online-bank">
    <Loader
                  loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"  
                useSystemClassLoaderAsParent="false"
    />
    </Context>
    If I include this I get the following:

    SEVERE: LifecycleException
    java.lang.NoClassDefFoundError: org/apache/catalina/loader/WebappClassLoader


    Here's my web.xml

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
            
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        
        <context-param>
            <param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/bank-servlet.xml</param-value>        
        </context-param>
        
        <servlet>
            <servlet-name>bank</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        </servlet>
        
        <servlet-mapping>
            <servlet-name>bank</servlet-name>
            <url-pattern>*.htm</url-pattern>
        </servlet-mapping>
        
    </web-app>
    As you can see it's really basic, just want to set up something simple on the mvc side to start with. I've already set a project up without the ContextLoaderListener where the DispatcherServlet picks up the context.xml with no problems based on the mapping but I want to figure out how to get the ContextLoaderListener working when running Tomcat from Eclipse. Hate just given up on something!

    Any tips/comments appreciated and apologies for such a long first post!

    /Edit: meant to edit this earlier but as I only registered on Saturday the post wasn't visible. Anyway it turned out my runtime configuration through Eclipse was causing a conflict. Removed all project jars from the classpath and was able to load without any additional configuration in tomcat.
    Last edited by DamoKen; Sep 7th, 2009, 02:16 PM. Reason: Fixed
Working...
X