views:

859

answers:

2

In my Tomcat logs (catalina) I am getting the following error preventing my application from starting up:

SEVERE: Error listenerStart
24-Mar-2009 13:23:10 org.apache.catalina.core.StandardContext start
SEVERE: Context [/exampleA] startup failed due to previous errors

I do not know why I am getting this. In my web.xml I have the following

<listener>
 <listener-class>
  uk.co.a.listener.SessionListener
 </listener-class>
</listener>

<listener>
 <listener-class>
  uk.co.a.listener.SessionAttributeListener
 </listener-class>
</listener>

When I comment out the listeners it starts up fine. The code for the listners are below:

public class SessionAttributeListener implements HttpSessionAttributeListener {
    static Log log = LogFactory.getLog(SessionAttributeListener.class.getName());

    public void attributeAdded(HttpSessionBindingEvent hsbe) {
     log.debug("VALUE attributeAdded to THE SESSION:" + hsbe.getName());
    }

    public void attributeRemoved(HttpSessionBindingEvent hsbe) {
     log.debug("VALUE attributeRemoved from THE SESSION:" + hsbe.getName());
    }

    public void attributeReplaced(HttpSessionBindingEvent hsbe) {
     log.debug("VALUE attributeReplaced in THE SESSION:" + hsbe.getName());
    }
}

and

public class SessionListener implements HttpSessionListener {

    static Log log = LogFactory.getLog(SessionListener.class.getName());

    private static int activeSessions = 0;
    public void sessionCreated(HttpSessionEvent evt)
    {
     activeSessions++;
     log.debug("No. of active sessions on:"+
       new java.util.Date()+" : "+activeSessions);
    }
    public void sessionDestroyed (HttpSessionEvent evt)
    {
     activeSessions--;
    }
}

Why is this not starting? Or where can I look for more information?

UPDATE

There only seems to be a problem with SessionAttributeListener from starting up. The SessionListener was not starting up because the <listener> were declared after the <servlet>

UPDATE

There was a problem with the JAR file used. The class for SessionAttributeListener was not included. When it was included the application started.

UPDATE

The AttributeListener does not seem to be running. When it is used the code fails. Is there a simple way to check if a listener is running?

A: 

re your update reading "The AttributeListener does not seem to be running. When it is used the code fails. Is there a simple way to check if a listener is running?" have you tried adding a static initialiser? something like

static {
log.debug("static initialiser called");
}

that way the first time that the class is referenced you should get a log record.

stjohnroe
A: 

When you encounter "startup failed due to previous errors" in your Tomcat logs, you will either find an exception further up in the log that is causing this issue or you need to fully configure logging within Tomcat such that the exception may be written to the logs. Once you have the root cause written to your logs, resolution is usually trivial.

Kyle W. Cartmell