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

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

问题描述

我一直在用@ViewScoped托管bean敲打头脑。我正在使用primeface的schedule组件来显示一些事件。当用户点击特定按钮时,使用ajax调用viewscoped bean中的方法,但每次我得到
java.io.NotSerializableException时,如果我更改了managed-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.NotSerializableException期间Tomcat部署 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.

我以前从未见过这个问题,谷歌似乎也没有对这个问题给予太多关注。根据您使用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应该可以解决这个问题:在@ViewScoped @ManagedBean中 @EJB导致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天全站免登陆