WebLogic 上的 GWT/RequestFactory 的 ClassCastException

发布于 2025-01-04 18:04:48 字数 1668 浏览 1 评论 0原文

我正在客户端设置基于 GWT/RequestFactory 的 GWT 应用程序,并在服务器端设置基于 WebLogic 的 JPA/EclipseLink。

然而,在开发过程中,每当我更改服务器端代码上的某些内容(可以是实体、DAO,甚至是 Java 文件中的注释!)时,我都会收到 2 之间的 ClassCastException 显然当我尝试使用我的应用程序时,类似的类,摆脱它的唯一方法是重新启动我的 WebLogic 服务器。即使重新部署应用程序也无济于事。

2012 年 2 月 10 日下午 4:08:10 com.google.web.bindery.requestfactory.server.RequestFactoryServlet doPost 严重:意外错误 java.lang.ClassCastException: com.mycompany.MyClass 无法转换为 com.mycompany.MyClass at com.mycompany.server.locator.CodeLevelLocator.getId(MyClassLocator.java:1) 在 com.google.web.bindery.requestfactory.server.LocatorServiceLayer.doGetId(LocatorServiceLayer.java:168) 在 com.google.web.bindery.requestfactory.server.LocatorServiceLayer.getId(LocatorServiceLayer.java:66) 在 com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.getId(ServiceLayerDecorator.java:81)

知道如何避免此服务器重新启动吗?

谢谢。

编辑:我正在为此设置赏金,因为每次服务器更改后重新启动 WebLogic 真的很痛苦!

EDIT2 通过添加以下 ServletContextListener 解决了 James 的问题:

public class DeploymentListener implements ServletContextListener {

    private static Logger log = LoggerFactory
            .getLogger(DeploymentListener.class.getName());

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {

        try {
            // close the Entity Manager Factory.
            EMF.close();
        } catch (Exception e) {
            log.error("Error closing the Entity Manager Factory", e);
        }
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        // nothing to do
    }

}

I'm setting up a GWT application based on GWT/RequestFactory on client side, and JPA/EclipseLink over WebLogic on server side.

However, during development, everytime I change something on the server-side code (it can be an entity, the DAO, or even a comment in a Java file!), I get a ClassCastException between 2 apparently similar classes when I try to use my application, and the only way to get rid of it is to restart my WebLogic server. Even redeploying the application doesn't help.

Feb 10, 2012 4:08:10 PM
com.google.web.bindery.requestfactory.server.RequestFactoryServlet
doPost SEVERE: Unexpected error java.lang.ClassCastException:
com.mycompany.MyClass cannot be cast to com.mycompany.MyClass at
com.mycompany.server.locator.CodeLevelLocator.getId(MyClassLocator.java:1)
at
com.google.web.bindery.requestfactory.server.LocatorServiceLayer.doGetId(LocatorServiceLayer.java:168)
at
com.google.web.bindery.requestfactory.server.LocatorServiceLayer.getId(LocatorServiceLayer.java:66)
at
com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.getId(ServiceLayerDecorator.java:81)

Any idea how to avoid this server restart?

Thanks.

EDIT: I'm setting up a bounty on this, because restarting WebLogic after each server change is really painful!!!

EDIT2 solved thanks to James by adding the following ServletContextListener:

public class DeploymentListener implements ServletContextListener {

    private static Logger log = LoggerFactory
            .getLogger(DeploymentListener.class.getName());

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {

        try {
            // close the Entity Manager Factory.
            EMF.close();
        } catch (Exception e) {
            log.error("Error closing the Entity Manager Factory", e);
        }
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        // nothing to do
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

稚气少女 2025-01-11 18:04:48

这是一个类加载器问题,在重新部署后,旧的类/实例仍保留在应用程序中的某个位置。

它可能与 JPA 有关,您使用的是容器管理的持久性单元还是应用程序管理的?容器管理不应该有这个问题,但应用程序管理可能会出现这个问题,就像您不关闭旧的 EntityManagerFactory 一样,它可以保留在旧的类中。确保在重新部署之前关闭所有工厂,或者尝试容器管理以查看是否可以解决问题。

This is a class loader issue, somehow after redeploying you have the old classes/instances remaining somewhere in your application.

It could be related to JPA, are you using a container managed persistence unit, or application managed? Container managed should not have this issue, but application managed could, as if you don't close the old EntityManagerFactory it can remain with the old classes. Ensure you close all factories before redeploying, or try container managed to see if it resolves the issue.

酒绊 2025-01-11 18:04:48

不熟悉在 Weblogic 上运行 GWT,但这也许会有所帮助。

在调试模式下运行服务器 - 它应该能够在运行时获取类/jar 更改。

也许您只需要重新发布服务器而不是重新启动它。

最后,您的类路径中其他位置的 jar 文件中是否有该类?

Not familiar with running GWT on Weblogic but perhaps this will help.

Run your server in debug mode - it should be able to pick up the class/jar changes at runtime.

Perhaps you only need to re-publish your server instead of restarting it.

Lastly, do you have that class in a jar file elsewhere in your class path?

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