In guice-snapshot20090205, if you have a ServletModule with two calls
to serve(path, myservlet) for the same servlet, you get two calls to
myservlet.init().  I believe this is wrong.

Existing state with web.xml configuration:
  <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>com.example.MyServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/new/place/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>//legacy/old/place/*</url-pattern>
  </servlet-mapping>

This results in only one call to MyServlet.init().  I believe this is
correct.

I transliterated this web.xml file to a
ServletModule.configureServlets method which does this:
  serve("/new/place/*").with(MyServlet.class);
  serve("/legacy/old/place/*").with(MyServlet.class);

MyServlet is marked as @Singleton.

When I use this module, MyServlet.init() iscalled twice.

I've stepped through ManagedServletPipeline.init and it just iterates
over the servlet definitions and calls init on each.  The two serve()
calls above result in two ServletDefinition objects.
ServletDefinition.init does check to make sure that the HttpServlet
bound to the servletKey has a Singleton binding, but it doesn't
protect against two ServletDefinition objects bound to the same
servletKey.

Leigh.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to