@ViewScoped 托管 bean 中的 @EJB 导致 java.io.NotSerializableException [英] @EJB in @ViewScoped managed bean causes java.io.NotSerializableException

查看:19
本文介绍了@ViewScoped 托管 bean 中的 @EJB 导致 java.io.NotSerializableException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用@ViewScoped 托管bean 敲我的头.我正在使用 primeface 的schedule"组件来显示一些事件.当用户单击特定按钮时,会使用 ajax 调用 viewscoped bean 中的一个方法,但每次我得到一个java.io.NotSerializableException",如果我更改托管 bean 范围以请求问题消失.

I've been banging my head around with a @ViewScoped managed-bean. I'm using primeface's "schedule" component in order to display some events. When the user clicks on a specific button a method in the viewscoped bean is called using ajax but every time I get a "java.io.NotSerializableException", if I change the managed-bean scope to request the problem dissapears.

我做错了什么?有什么想法吗?

What am I doing wrong? any ideas?

这是我的托管 bean:

here is my managed bean :

@ManagedBean(name = "schedule")
@ViewScoped
public class ScheduleMBean implements Serializable {

    @EJB
    private CongeBean congeBean;


    @ManagedProperty(value = "#{sessionBean}")
    private SessionMBean sessionBean;

    private DefaultScheduleModel visualiseurConges = null;

    public ScheduleMBean(){

    }
    @PostConstruct
    public void init() {

        if(visualiseurConges == null){

                visualiseurConges = new DefaultScheduleModel();
        }



    }

    public void updateSchedule(){

        visualiseurConges.addEvent(new DefaultScheduleEvent("test" , new Date(), new Date() ));



    }

    public void setVisualiseurConges(DefaultScheduleModel visualiseurConges) {
        this.visualiseurConges = visualiseurConges;
    }

    public DefaultScheduleModel getVisualiseurConges() {



        return visualiseurConges;
    }

    public void setSessionBean(SessionMBean sessionBean) {
        this.sessionBean = sessionBean;
    }

    public SessionMBean getSessionBean() {
        return sessionBean;
    }



}

这里是完整的堆栈跟踪

GRAVE: java.io.NotSerializableException: fr.novae.conseil.gestion.ejb.security.__EJB31_Generated__AuthenticationBean__Intf____Bean__
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at java.util.HashMap.writeObject(HashMap.java:1001)
    at sun.reflect.GeneratedMethodAccessor592.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1338)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1146)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at java.util.HashMap.writeObject(HashMap.java:1001)
    at sun.reflect.GeneratedMethodAccessor592.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at com.sun.faces.renderkit.ClientSideStateHelper.doWriteState(ClientSideStateHelper.java:293)
    at com.sun.faces.renderkit.ClientSideStateHelper.writeState(ClientSideStateHelper.java:167)
    at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:123)
    at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:155)
    at org.primefaces.application.PrimeFacesPhaseListener.writeState(PrimeFacesPhaseListener.java:174)
    at org.primefaces.application.PrimeFacesPhaseListener.handleAjaxRequest(PrimeFacesPhaseListener.java:111)
    at org.primefaces.application.PrimeFacesPhaseListener.beforePhase(PrimeFacesPhaseListener.java:74)
    at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    at java.lang.Thread.run(Thread.java:619)

提前致谢

推荐答案

@ViewScoped bean 存储在 HTTP 会话中.任何存储在 HTTP 会话中的对象都需要实现 可序列化.另请参见 JSF 托管 bean 导致 java.io.NotSerializableExceptionTomcat 部署java.io.WriteAbortedException:写入中止;java.io.NotSerializableException.

@ViewScoped beans are stored in HTTP session. Any objects which are stored in the HTTP session needs to implement Serializable. See also JSF managed bean causing java.io.NotSerializableException during Tomcat deployment and java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException.

NotSerializableException 通常是不言自明的,因为它提到了需要序列化的类的全限定名称,但不能,因为它没有实现 Serializable.

The NotSerializableException is usually self-explaining since it mentions the full qualified name of the class which needs to be serialized as well, but can't be since it doesn't implement Serializable.

但是,在这种特殊情况下,名称似乎表示一个自动生成的类,很可能是由 EJB 容器自动生成的,因此完全不受您的控制.

However, in this particular case the name seems to indicate an autogenerated class, most likely autogenerated by the EJB container and thus completely out of your control.

我以前从未见过这个问题,而且 Google 似乎也没有给出太多关于这个问题的信息.根据您使用 Glassfish v3 的堆栈跟踪,我建议发布一个 问题 关于那个.同时,您最好的选择可能是将 JSF 视图状态保存到服务器端.

I've never seen this problem before and Google also doesn't seem to give much about this problem. Based on the stacktrace you're using Glassfish v3, so I'd suggest to post an issue about that. In the meanwhile your best bet is probably to set the JSF view state saving to the server side instead.

更新:MyFaces 中的一个类似问题表明 JSF impl 特定问题在反序列化期间使用错误的类加载器.升级 JSF impl 应该可以解决问题:@EJB in @ViewScoped @ManagedBean导致 java.io.NotSerializableException.

Update: a similar problem in MyFaces suggests a JSF impl specific issue of using wrong classloader during deserialization. Upgrading the JSF impl should solve the problem: @EJB in @ViewScoped @ManagedBean causes java.io.NotSerializableException.

这篇关于@ViewScoped 托管 bean 中的 @EJB 导致 java.io.NotSerializableException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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