I'm trying to figure out how to Singleton bind 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 here is that both servelets the app needs to serve is a third-party library (Restlet and GAE).
The exception thrown 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 deal with this when the servlets is a third-party library that can't be modified at least at this point. Is there a work-around to make this work?
The solution is to add:
bind(RemoteApiServlet.class).in(Scopes.SINGLETON);
bind(ServerServlet.class).in(Scopes.SINGLETON);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With