Getting java.io.NotSerializableException with a spring service when stopping tomcat

后端 未结 4 1307
遇见更好的自我
遇见更好的自我 2021-01-13 11:11

i am using spring 3 with JSF 2 and i replaced JSF managed beans with spring beans, by adding on top of bean:

@Component(\"mybean\")
@Scope(\"session\")
         


        
4条回答
  •  死守一世寂寞
    2021-01-13 11:46

    You get this exception because the class does not implement Serializable. Tomcat serializes currently running HttpSession objects including all its attributes to disk whenever it is about to restart/redeploy, so that they are revived after the cycle. Session scoped objects are stored as attributes of the HttpSession, hence they need to implement Serializable to survive the restart/redeploy as well.

    If you would like to make them Serializable, then implement it accordingly:

    public class YourSpringService implements Serializable {}
    

    Otherwise, just ignore the exception or turn off serializing sessions to disk in Tomcat's config.

    Note that the same story also applies to JSF view/session scoped beans.

提交回复
热议问题