【问题标题】:Spring: Invoking a method before session timeoutSpring:在会话超时之前调用方法
【发布时间】:2013-05-29 04:30:37
【问题描述】:

我目前有一个 Spring 3 项目,我想做的是在会话到期时检索我的会话。我一直在做一些研究,显然HttpSessionBindingListener 可以处理这个问题,尽管在一个 Spring 项目中,我似乎无法弄清楚如何正确地实现它。在我的会话中,我保存了一个 UserDetailsImpl 对象,其中包含我的 User 对象。我应该在所述对象上实现HttpSessionBindingListener 吗?

明确地说,我想要做的是在会话对象过期之前检索用户的 ID。

编辑:显然HttpSessionBindingListener 在 Websphere 中无法正常工作,但在 Tomcat 中可以。还有其他选择吗?

【问题讨论】:

    标签: spring session timeout


    【解决方案1】:

    您也可以在web.xml注册监听器:

    <listener>
        <listener-class>com.example.MyHttpSessionListener</listener-class>
    </listener>
    

    并使用方法sessionDestroyed()

    此答案中有详细描述:https://stackoverflow.com/a/3720512/516167

    Inject Spring Application Context in this Listener like is described in this question:

    How to inject dependencies into HttpSessionListener, using Spring?

    此处描述了其他可能的解决方案:

    Logout/Session timeout catching with spring security

    【讨论】:

      猜你喜欢
      • 2013-09-18
      • 2011-04-25
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      • 2014-07-18
      • 2011-10-18
      相关资源
      最近更新 更多