Search code examples
javaservletsservlet-listeners

Multiple listeners in web.xml?


How do I specify multiple listener classes in web.xml? I tried searching the web without luck.

I tried the following, but it seems that it doesn't work:

<listener>
    <listener-class>
        org.obliquid.web.StartAndStop
    </listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

Solution

  • That is the correct syntax. What "didn't work"? It's not this bit, unless perhaps you mean there's an XML parsing error because it's in the wrong place in the doc.

    EDIT: the 'right' place if I recall correctly is before <servlet> but I am not sure if the latest XSD schemas do restrict that. You would get a clear parsing error if this was the problem.