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

后端 未结 1 1826
生来不讨喜
生来不讨喜 2020-12-16 17:00

At deployment of my webApplication on Tomcat 7 I am getting the console output below. After restarting the server twice or three times it works without exceptions.

I

相关标签:
1条回答
  • 2020-12-16 17:27

    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:

    • Tomcat 7.0 Configuration Reference - The Context container
    • java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException
    0 讨论(0)
提交回复
热议问题