因此,我尝试在HttpSession托管bean上的@PreDestroy方法上访问@PreDestroy的一个属性
session.getAttribute("myAttribute"); 但我得到了一个
java.lang.IllegalStateException: getAttribute: Session has already been invalidated为什么?
在销毁会话bean之前,我需要访问到该会话打开的外部服务的连接列表,当然,它们存储在会话属性对象上。
我怎么能这么做?
发布于 2016-02-19 08:19:35
显式访问会话作用域托管bean中的会话属性是没有意义的。只需使该属性成为会话作用域托管bean本身的属性即可。
@SessionScoped
public class YourSessionScopedBean implements Serializable {
private Object yourAttribute; // It becomes a session attribute already.
@PreDestroy
public void destroy() {
// Just access yourAttribute directly, no need to do it the hard way.
}
}发生异常的原因是会话通过HttpSession#invalidate()调用显式失效,而不是“仅过期”。
https://stackoverflow.com/questions/35488816
复制相似问题