【问题标题】:Why do my Spring Sessions keep getting deleted from my JDBC store?为什么我的 Spring Sessions 不断从我的 JDBC 存储中删除?
【发布时间】:2016-07-29 04:10:54
【问题描述】:

我正在使用带有 Postgres 的 Spring Sessions。会话使用JdbcOperationsSessionRepository 持久化到我的 Postgres 数据库中。

我用于会话的默认非活动时间是 30 天。用户登录后,我会使用 request.getSession().setMaxInactiveInterval() 并将其更改为 180 天。

但是由于某种原因,180 天没有得到尊重,并且会话每小时都会被删除。例如:

此会话应持续 180 天,但在下一小时开始时就被删除了。

有谁知道我可以如何阻止这些会话被删除并让它们保留 180 天?

我猜this function 与此有关。

这是我的应用程序中延长用户最大不活动时间间隔的部分:

private void setupSession(HttpServletRequest request, User user) {
   HttpSession session = request.getSession();
   session.setMaxInactiveInterval(15552000);
   session.setAttribute("user-id", user.id);
}

【问题讨论】:

标签: java spring postgresql session spring-session


【解决方案1】:

如 cmets 所示,这是 Spring Session JDBC 集成的问题,已在 gh-580 中报告。

要在解决方案交付之前解决此问题,您可以扩展 JdbcOperationsSessionRepository 并覆盖 cleanUpExpiredSessions 方法。之后,您只需要通过提供扩展 JdbcOperationsSessionRepository 并命名为 sessionRepository 的 bean 来覆盖默认的 JDBC 会话存储库 bean(bean 名称很重要,因为它必须与 JdbcHttpSessionConfiguration 中的名称匹配才能覆盖它) .

例如:

@EnableJdbcHttpSession
class SessionConfig {

    // omitted data source & tx manager config

    @Bean
    MyJdbcOperationsSessionRepository sessionRepository(...) {
        return new ...
    }

}

您可以在gh-580 的 cmets 中找到cleanUpExpiredSessions 的解决方案。

【讨论】:

  • 感谢@AzhaguSurya 的轻推,我已经更新了错误链接。
猜你喜欢
  • 2013-11-10
  • 2018-10-26
  • 1970-01-01
  • 1970-01-01
  • 2023-04-10
  • 2018-12-20
  • 1970-01-01
  • 1970-01-01
  • 2015-04-15
相关资源
最近更新 更多