2013-01-03 22 views
0

我使用的检票与EJB 3,当我把我的页面,日志告诉我一个错误检票系列化JNDI

Error serializing object class com.mk.view.page.CountryList [object=[Page class = com.mk.view.page.CountryList, id = 91, render count = 1]] 
org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException: The object type is not Serializable! 
A problem occurred while checking object with type: javax.naming.InitialContext 
Field hierarchy is: 
    91 [class=com.mk.view.page.CountryList, path=91] 
    private javax.naming.Context com.mk.view.page.CountryList.ctx [class=javax.naming.InitialContext] <----- field that is causing the problem 

我的代码是

public class CountryList extends Layout { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 
    /** 
    * 
    */ 


    private javax.naming.Context ctx; 
    private GenericCrudService sf; 



    private CountryList(){  
     try { 

       ctx = new javax.naming.InitialContext(); 
       sf = (GenericCrudService) ctx 
         .lookup("java:global/mkEar/mkEJB/CrudService!com.mk.business.common.GenericCrudService"); 

     } catch (NamingException e) { 
      e.printStackTrace(); 
     } 

     addModelModule(); 
     addSearchModule(); 
    } 

我的应用程序不会崩溃,我还没有找到这些解决方案,所以我不知道这些会比日志更糟?有谁知道解决这个问题

回答

1

不要将对GenericCrudService的引用保留为字段(也不要保留InitialContext实例)。将查找代码重构为方法,并在每次需要该服务时检索它。您可以重用它,但将它保留在本地(变量)或请求范围内。 AFAIK,不保证从JNDI查找返回的EJB是可序列化的,即使它们实现了接口并遵循序列化规则。容器可能会直接返回代理,而不是对象实例。

由于Wicket会在请求后序列化有状态页面,因此它们不能具有不可序列化的属性。这是你得到的错误的原因。

+0

非常感谢,这工作正常! Agora que vi que vcébrasileiro,vlwaí –

0

您还可以在组件onAttach/onConfigure方法中标记您的GenericCrudService字段瞬态并初始化实例。在使用Spring时,Wicket中会有一个专用注释@SpringBean,它将使您的不可序列化的服务字段成为您的代理并处理实例设置。