Guice Singleton Servlet Third-Party Service Binding

I am trying to understand how Singleton binds a servlet for my code:

public class GuiceServletModule extends ServletModule { @Override protected void configureServlets() { Map<String, String> params = new HashMap<String, String>(); params.put("org.restlet.application", "com.mycomp.server.RestletApplication"); serve("/rest/*").with(org.restlet.ext.servlet.ServerServlet.class, params); serve("/remote_api").with(com.google.apphosting.utils.remoteapi.RemoteApiServlet.class); } } 

The problem is that both applications that need to be served are a third-party library (Restlet and GAE).

The exception is:

 [INFO] javax.servlet.ServletException: Servlets must be bound as singletons. Key[type=org.restlet.ext.servlet.ServerServlet, annotation=[none]] was not bound in singleton scope. 

How can I handle this when servlets are a third-party library that cannot be changed at least for now. Is there any work to do this work?

+8
java google-app-engine servlets guice
source share
1 answer

The solution is to add:

  bind(RemoteApiServlet.class).in(Scopes.SINGLETON); bind(ServerServlet.class).in(Scopes.SINGLETON); 
+12
source share

All Articles