JSF managed bean causing java.io.NotSerializableException during Tomcat deployment

倖福魔咒の 提交于 2019-11-29 03:47:42
BalusC

Here's the relevant bit of the trace:

SCHWERWIEGEND: Exception loading sessions from persistent storage
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.dhbw.stg.wwi2008c.mopro.ui.viewscoped.MachineReservationListBean
     ...
     at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1576)
     at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1059)
     at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:284)
     at org.apache.catalina.session.StandardManager.load(StandardManager.java:204)
     at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:465)
     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
     ...

This one concerns a different problem than the question which you linked. By default, when Tomcat shutdowns, it will serialize the HttpSession to disk which will then be reloaded from disk on startup so that the endusers can just continue with the browser session without losing any session data.

In such case, any session attribute is supposed to implement Serializable. The JSF view state is by default stored in the session, including all appropriate view scoped beans. They needs to implement Serializable as well in order to survive a Tomcat shutdown/restart.

Technically, you can just ignore it. JSF will recreate the session/view scoped beans anyway when not present yet. However, the enduser won't be able to continue with the same session/view scoped data. Those exceptions won't occur when the session doesn't contain any non-serializable objects. That's why it "sometimes" works.

If you want to disable session persistence altogether so that you won't be bothered with those exceptions/warnings, then you need to add a <Manager> element with an empty pathname attribute to the <Context> element of the webapp in question.

<Context ... >
    <Manager pathname="" />
</Context>

This basically instructs Tomcat to use no session manager at all.

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!