WebLogic上具有GWT/RequestFactory的ClassCastException [英] ClassCastException with GWT/RequestFactory on WebLogic

查看:159
本文介绍了WebLogic上具有GWT/RequestFactory的ClassCastException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在客户端基于GWT/RequestFactory设置一个GWT应用程序,并在服务器端基于WebLogic设置JPA/EclipseLink.

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

但是,在开发过程中,每次我在服务器端代码上进行一些更改(它可以是实体,DAO甚至是Java文件中的注释!)时,我都会在2个看似相似的类之间得到一个ClassCastException当我尝试使用应用程序时,摆脱它的唯一方法是重新启动WebLogic服务器.甚至重新部署应用程序也无济于事.

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.

2012年2月10日下午4:08:10 com.google.web.bindery.requestfactory.server.RequestFactoryServlet doPost严重:意外错误java.lang.ClassCastException: com.mycompany.MyClass无法转换为com.mycompany.MyClass 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)

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?

谢谢.

EDIT :我为此设置了赏金,因为每次更改服务器后重新启动WebLogic确实很痛苦!!

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

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

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
    }

}

推荐答案

这是一个类加载器问题,在以某种方式重新部署您后,旧类/实例仍保留在应用程序中.

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

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

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.

这篇关于WebLogic上具有GWT/RequestFactory的ClassCastException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆