gpt4 book ai didi

java - @ViewScoped 托管 bean 中的 @EJB 导致 java.io.NotSerializableException

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:11:29 25 4
gpt4 key购买 nike

我一直在用@ViewScoped 托管 bean 来解决我的问题。我正在使用 primeface 的“计划”组件来显示一些事件。当用户单击特定按钮时,将使用 ajax 调用 viewscoped bean 中的方法,但每次我得到一个“java.io.NotSerializableException”,如果我更改托管 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 session 中。存储在 HTTP session 中的任何对象都需要实现 Serializable .另见 JSF managed bean causing java.io.NotSerializableException during Tomcat deploymentjava.io.WriteAbortedException: writing aborted; java.io.NotSerializableException .

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

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

我以前从未见过这个问题,谷歌似乎也没有提供太多关于这个问题的信息。基于您使用的是 Glassfish v3 的堆栈跟踪,所以我建议发布 issue关于那个。与此同时,您最好的选择可能是将 JSF View 状态保存设置为服务器端。


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

关于java - @ViewScoped 托管 bean 中的 @EJB 导致 java.io.NotSerializableException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3037722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com