gpt4 book ai didi

java - 用于第三方 servelet 的 Guice Singleton Servlet Binding 解决方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:39:59 31 4
gpt4 key购买 nike

我正在尝试弄清楚如何为我的代码单例绑定(bind)一个 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 是第三方库,至少目前无法修改时,我该如何处理。是否有解决方法来完成这项工作?

最佳答案

解决方法是添加:

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

关于java - 用于第三方 servelet 的 Guice Singleton Servlet Binding 解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28449254/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com