@EscBed @EJB中的托管bean会导致java.io.NotSerializableException

前端之家收集整理的这篇文章主要介绍了@EscBed @EJB中的托管bean会导致java.io.NotSerializableException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在用@ViewScoped托管bean敲打我的头.我正在使用表单的“schedule”组件来显示一些事件.当用户点击某个特定的按钮时,viewscoped bean中的一个方法是使用ajax调用的,但是每次我得到一个
java.io.NotSerializableException”,如果我更改managed-bean范围以请求解决问题.

我究竟做错了什么?有任何想法吗?

这是我的托管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会话中的任何对象都需要实现 Serializable.另请参见 JSF managed bean causing java.io.NotSerializableException during Tomcat deploymentjava.io.WriteAbortedException: writing aborted; java.io.NotSerializableException.

NotSerializableException通常是自解释的,因为它提到了需要序列化的类的完整限定名,但不能因为它不实现Serializable.

然而,在这种特殊情况下,这个名称似乎表示一个自动生成的类,很可能由EJB容器自动生成,因此完全脱离了你的控制.

我以前从来没有看到这个问题,Google似乎也没有太多关于这个问题.基于stacktrace,你使用的是Glassfish v3,所以我建议发布一个issue.同时您最好的选择是将JSF视图状态设置为服务器端.

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

原文链接:https://www.f2er.com/java/123070.html

猜你在找的Java相关文章