创建会话范围的受管bean时,可序列化接口的重要性 [英] Importance of Serializable interface while creating a session scoped managed bean

查看:91
本文介绍了创建会话范围的受管bean时,可序列化接口的重要性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白序列化在会话范围内的JSF托管Bean中如何工作.为什么创建会话范围的JSF托管bean时Serializable接口的实现为什么很重要?

I can't understand how serialization works in session scoped JSF managed beans. Why is implementation of Serializable interface important while creating a session scoped JSF managed bean?

推荐答案

@SessionScoped bean最终存储在用户的HTTP会话中.

@SessionScoped beans are ultimately stored in the user's HTTP session.

这意味着当Java EE部署实现会话保留方案时(例如,tomcat将在服务器关闭时尝试将当前会话保存到 .ser 文件中, if 部署者选择的方式),则这些会话作用域的Bean也将成为将要保留的有效负载的一部分.

This means that when a Java EE deployment implements a session preservation scheme (for example, tomcat will attempt to save current sessions to a .ser file on server shutdown, if the deployer so chooses), those session-scoped beans would also be part of the payload that will be persisted.

无法序列化的会话作用域bean在这里成为问题,因为它使整个HTTP会话成为其一部分,并且是不可持久的(尝试序列化包含不可序列化成员的对象将导致,但有一些特殊处理)

A session scoped bean that isn't serializable becomes a problem here as it renders the entire HTTP session that it is a part of, un-persistable (any attempt to serialize an object that contains an unserializable member will cause a NotSerializableException, except with some special handling)

顺便说一句,这意味着即使您的会话范围的bean实现了 Serializable ,其所有成员变量也必须可序列化或标记为transient.

Incidentally, that means that even if your session-scoped bean implements Serializable, all its member variables must either be serializable or be marked transient.

简而言之,给定HTTP会话的易于通过序列化保留的整个对象图,必须标记为可序列化或transient

In short, the entire object graph of a given HTTP session that is liable to be persisted via serialization, must either be marked as serializable or transient

了解更多:

关于序列化的JavaBean建议

这篇关于创建会话范围的受管bean时,可序列化接口的重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆