将 GWT RequestFactory 与 Grails 一起使用时的类加载器问题
为了让 GWT RequestFactory 与 Grails 一起运行,我使用以下方法:
class GwtController extends RequestFactoryServlet {
public GwtController() {
super()
}
def index = {
doPost request, response
}
@Override
public ServletContext getServletContext() {
return ServletContextHolder.servletContext
}
@Override
public ServletConfig getServletConfig() {
return new DummyServletConfig(getServletContext(),"grails");
}
}
其中 DummyServletConfig 是 ServletConfig 的简单实现
这在将应用程序部署到 tomcat 时有效。然而,使用测试或开发模式,则不然。我需要调整 GWT Servlet,以防止它使用错误的类加载器:
在第 46 行中,我更改
private static final RequestFactoryInterfaceValidator validator =
new RequestFactoryInterfaceValidator(log,
new RequestFactoryInterfaceValidator.ClassLoaderLoader(
ServiceLayer.class.getClassLoader()));
为
private static final RequestFactoryInterfaceValidator validator = new RequestFactoryInterfaceValidator(
log, new RequestFactoryInterfaceValidator.ClassLoaderLoader(
Thread.currentThread()
.getContextClassLoader()));
否则,它将找不到我的 Domain 类(显然不驻留在 GrailsRootLoader 中,而是驻留在 Thread 的类中)装载机)。
现在我想将我的 GWT servlet 恢复为 Google 发布的官方二进制文件,我想知道如何修复 Grails 中不正确的 ClassLoader 或使 RequestFactoryServlet 正常工作而不更改 GWT 源。
In order to get GWT RequestFactory running with Grails, I am using the following approach:
class GwtController extends RequestFactoryServlet {
public GwtController() {
super()
}
def index = {
doPost request, response
}
@Override
public ServletContext getServletContext() {
return ServletContextHolder.servletContext
}
@Override
public ServletConfig getServletConfig() {
return new DummyServletConfig(getServletContext(),"grails");
}
}
where DummyServletConfig is a simple implementation of ServletConfig
This is working when deploying the app to tomcat. However, using testing or development mode, it is not. I was required to adjust the GWT Servlet in order to prevent it from using the wrong Class Loader:
In line 46 I changed
private static final RequestFactoryInterfaceValidator validator =
new RequestFactoryInterfaceValidator(log,
new RequestFactoryInterfaceValidator.ClassLoaderLoader(
ServiceLayer.class.getClassLoader()));
to
private static final RequestFactoryInterfaceValidator validator = new RequestFactoryInterfaceValidator(
log, new RequestFactoryInterfaceValidator.ClassLoaderLoader(
Thread.currentThread()
.getContextClassLoader()));
Otherwise, it wouldn't find my Domain classes (which apparently do not reside in the GrailsRootLoader but in the Thread's class loader).
Now I would like to revert my GWT servlet to the official binary released by Google and I wonder how I can fix the incorrect ClassLoader in Grails or make the RequestFactoryServlet work correctly without altering the GWT source.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望 GWT 2.3 能够解决您的问题:
http:// /code.google.com/p/google-web-toolkit/issues/detail?id=6092
I hope that GWT 2.3 will fix your problem:
http://code.google.com/p/google-web-toolkit/issues/detail?id=6092