将 GWT RequestFactory 与 Grails 一起使用时的类加载器问题

发布于 2024-11-02 00:22:00 字数 1384 浏览 3 评论 0原文

为了让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文