【问题标题】:Spring Session with Redis - server.session.timeout has no effect带有 Redis 的 Spring Session - server.session.timeout 无效
【发布时间】:2018-08-28 12:48:21
【问题描述】:

我按照此文档在我的 Spring Boot 应用程序中设置会话:https://docs.spring.io/spring-session/docs/current/reference/html5/guides/boot-redis.html

application.properties

spring.session.store-type=redis
server.session.timeout=10

发送请求后,我在redis中看到如下记录:

127.0.0.1:6379> keys *
1) "spring:session:sessions:4b524c1e-e133-4d04-8b5b-40ffc3685af3"
2) "spring:session:sessions:expires:c1e2792f-f001-4a02-b812-39ab68f719ea"
3) "spring:session:sessions:expires:4b524c1e-e133-4d04-8b5b-40ffc3685af3"
4) "spring:session:index:org.springframework.session.FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME:105121963489487663346"
5) "spring:session:expirations:1521492480000"

我预计这些记录会在 10 秒后消失(因为 server.session.timeout 属性),但数据会在几分钟后保留。

如何在 Spring Sessions 中正确设置会话超时?

【问题讨论】:

    标签: spring session redis timeout spring-session


    【解决方案1】:

    您正在使用已弃用的 server.session.timeout,它在 Spring Boot 2.0 中已替换为 server.servlet.session.timeout。从PR I've opened against your sample repo 更改后,所需的会话超时将正确应用。

    请花点时间熟悉Spring Boot 2.0 Migration Guide并考虑使用spring-boot-properties-migrator模块。

    【讨论】:

      【解决方案2】:

      根据 Vedran 的回答并不完全正确,因为 Springboot 通用属性具有这两个属性,当前都处于活动状态且未弃用。

      Springboot common properties

      春季课程:

      spring.session.timeout= # Session timeout. If a duration suffix is not specified, seconds will be used.
      

      用于网络属性

      网络属性 嵌入式服务器配置(服务器属性)

      server.servlet.session.timeout= # Session timeout. If a duration suffix is not specified, seconds will be used.
      

      【讨论】:

        【解决方案3】:

        我也遇到过这个问题,可惜我无法通过设置“spring.session.timeout”和“server.servlet.session.timeout”来有效控制会话超时。 我的解决方案是通过注解来配置会话超时。

        @EnableRedisHttpSession(maxInactiveIntervalInSeconds = 30)
        

        【讨论】:

          猜你喜欢
          • 2021-12-10
          • 2016-12-09
          • 2017-11-02
          • 2017-04-02
          • 2021-09-13
          • 2019-02-12
          • 2016-07-08
          • 2017-01-08
          • 2016-05-31
          相关资源
          最近更新 更多