【发布时间】:2010-05-14 20:22:27
【问题描述】:
我已经使用 Guice 配置了我的 GWT 应用程序,如 here 所述。通过此设置,应用可以正常工作。
但是我现在想做的是让 GWTTestCase 使用 GWT RPC 调用服务。为此我做了这个,
- 更新了我的
JUnit.gwt.rpc 以便服务 URL 映射到 GuiceRemoteServiceServlet - 为 GuiceRemoteServiceServlet 添加了一个 init() 方法来按照this comment 初始化 Injector
很遗憾,我仍然遇到错误,
com.google.inject.ProvisionException: Guice provision errors:
Caused by: com.google.inject.OutOfScopeException: Cannot access scoped object. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
at com.google.inject.servlet.GuiceFilter.getContext(GuiceFilter.java:132)
at com.google.inject.servlet.GuiceFilter.getRequest(GuiceFilter.java:118)
at com.google.inject.servlet.InternalServletModule$1.get(InternalServletModule.java:35)
.....
它试图提供的对象是 ServletContext。错误的原因是 GuiceFilter 没有被调用,所以 ServletContext 没有绑定到 ThreadLocal。
有什么办法可以解决吗?
【问题讨论】: