Bug 44268 - Multiple registrations of same ServletContextListener class not possible
Summary: Multiple registrations of same ServletContextListener class not possible
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.14
Hardware: Other Linux
: P2 enhancement (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2008-01-18 08:42 UTC by Stefan Fleiter
Modified: 2014-02-17 13:56 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Fleiter 2008-01-18 08:42:18 UTC
When I register the same class implementing ServletContextListener twice or more
its' contextInitialized methods only gets called once.

The servlet specifications (2.4 and 2.5) say the conforming container has to 
call the listeners in the same order they are registered in the deployment
The case that one listener class is registered twice is not mentioned
explicitly in the specification, though.


test.ServletContextListener1 and test.ServletContextListener2 get called,
but test.ServletContextListener1 does not get called again.

Apache Tomcat 5.5.25 has the same bug.
Comment 1 Mark Thomas 2008-01-18 12:11:49 UTC
This is explicitly not allowed as a fix for

The change is here http://svn.apache.org/viewvc?view=rev&revision=287588

The problem is that it is hard to distinguish between when multiple listeners is
a bug (ie 3770) and when it is intentional (this issue).

There are a few places where the spec could be read as only expecting one
instance of each listener class per webapp but it is far from clear.

I am going to resolve this as WONTFIX since working around this issue is easier
than trying working around 3770.
Comment 2 Stefan Fleiter 2008-01-21 01:15:49 UTC
Thanks a lot for your fast reply.

Yes I already recognized the spec is not that clear on this issue.
Could you at least print a warning log message if a listener is registered more
than once?
Comment 3 Mark Thomas 2008-01-21 13:17:38 UTC
A warning seems reasonable. Re-opening and changing this to an enhancement.

I've committed a fix to trunk and proposed it for 6.0.x. It probably won't make
the 6.0.16 release but should make the following one.
Comment 4 Mark Thomas 2008-01-28 13:26:33 UTC
This did make it into 6.0.16.
Comment 5 Stefan Fleiter 2008-01-29 01:07:53 UTC
Thanks a lot Mark!
This will definitely help the next one running into this.
Comment 6 Tom Harris 2008-02-20 10:43:19 UTC
When upgrading our developer boxes to tomcat 6.0.16, the following message is
now appearing for many of the listeners that we use. Each of our webapps has one
and only one listener defined of each class, but we are now getting the "The
listener {0} is already configured for this context. The duplicate definition
has been ignored."
So, what's going on here? Should I just ignore these messages? Why are they
showing up when it's clear that there are no duplicate definitions? Where else
could these listener definitions be besides in the webapp's web.xml? Should I
open a new ticket in Bugzilla? Or should this ticket be reopened?
Comment 7 Mark Thomas 2008-02-20 14:23:11 UTC
This enhancement uncovered a bug where all listeners in web.xml were registered
twice. See bug 44423.