简体   繁体   中英

java.io.NotSerializableException: org.apache.catalina.session.StandardSessionFacade

When I deploy my webapp, I see this error message

com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/qtl.xhtml]
java.io.NotSerializableException: org.apache.catalina.session.StandardSessionFacade
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
at java.util.HashMap.writeObject(HashMap.java:1001)
...

I research around and this error might be because I try to serialize attribute that non-serializable. So I have an ApplicationScoped managed bean that look like below

@ManagedBean
@ApplicationScoped
public class ApplicationBean implements Serializable {

    private Map<String, HttpSession> logins; 
    ...
}

Can Map<String, HttpSession> logins be Serializable?

Tomcat 7

The HttpSession is indeed not serializable. The application scoped bean should also not be serializable after all. Remove the implements Serializable from the application scoped bean class and don't inject it as managed property of a session or view scoped bean. Instead, inject it in a request scoped bean only or grab it from the application map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM