1

If I relate to the documentation of Guice I can :

completely eliminate web.xml from your servlet application

But I can't find a way to create a servlet listener from Guice so I still need the web.xml file.

Do I missed something or is it really impossible ?

Jib'z
  • 953
  • 1
  • 12
  • 23
  • Possible duplicate of [Do I really need web.xml for a Servlet based Java web application?](http://stackoverflow.com/questions/30259153/do-i-really-need-web-xml-for-a-servlet-based-java-web-application) – Jaumzera Jun 01 '16 at 02:43

1 Answers1

1

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.

sargue
  • 5,695
  • 3
  • 28
  • 43