I assume that by servlet listener you mean a ServletContextListener
. You are using the Guice ServletModule
. You should use (and probably are using right now if following Guice documentation) the GuiceServletContextListener
also to bootstrap your modules.
In this situation you want to throw your own ServletContextListener
and not write a web.xml
. You can do that. You have several options.
You can just add the @WebListener
annotation to your class.
@WebListener
public class MyListener implements ServletContextListener {
...
That has a problem (for me). You have two listeners (this one and the guice derived one) but you don't know which one goes first.
My solution for this is to just have one (the guice one) which calls my other, general purpose, listener.