【问题标题】:Guice Singleton Servlet Binding work-around for third-party servelets第三方小服务程序的 Guice Singleton Servlet Binding 解决方法
【发布时间】:2015-04-11 12:33:23
【问题描述】:

我正在尝试弄清楚如何为我的代码单例绑定一个 servlet:

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);
    }
}

这里的问题是应用程序需要服务的两个servelet 都是第三方库(Restlet 和GAE)。

抛出的异常是:

[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.

当 servlet 是至少目前无法修改的第三方库时,我该如何处理。是否有解决方法来完成这项工作?

【问题讨论】:

    标签: java google-app-engine servlets guice


    【解决方案1】:

    解决方法是添加:

        bind(RemoteApiServlet.class).in(Scopes.SINGLETON);
        bind(ServerServlet.class).in(Scopes.SINGLETON);
    

    【讨论】:

      猜你喜欢
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      • 1970-01-01
      相关资源
      最近更新 更多