spring项目中将sessionid对应的cookie过期时间设置很长,但是实际session还是在半个小时后失效,跟了一下代码,spring中session实现接口为

org.springframework.session.SessionRepository

public interface SessionRepository<S extends Session> {
S createSession(); void save(S var1); S findById(String var1); void deleteById(String var1);
}

这个接口有两个实现类:

MapSessionRepository
RedisOperationsSessionRepository

单机环境使用前者,分布式环境使用后者,来看后者代码:

org.springframework.session.data.redis.RedisOperationsSessionRepository

    public RedisOperationsSessionRepository.RedisSession createSession() {
RedisOperationsSessionRepository.RedisSession redisSession = new RedisOperationsSessionRepository.RedisSession();
if(this.defaultMaxInactiveInterval != null) {
redisSession.setMaxInactiveInterval(Duration.ofSeconds((long)this.defaultMaxInactiveInterval.intValue()));
} return redisSession;
}

org.springframework.session.data.redis.RedisOperationsSessionRepository.RedisSession

        RedisSession() {
this(new MapSession());
this.delta.put("creationTime", Long.valueOf(this.getCreationTime().toEpochMilli()));
this.delta.put("maxInactiveInterval", Integer.valueOf((int)this.getMaxInactiveInterval().getSeconds()));
this.delta.put("lastAccessedTime", Long.valueOf(this.getLastAccessedTime().toEpochMilli()));
this.isNew = true;
this.flushImmediateIfNecessary();
} public boolean isExpired() {
return this.cached.isExpired();
}

org.springframework.session.MapSession

    public boolean isExpired() {
return this.isExpired(Instant.now());
} boolean isExpired(Instant now) {
return this.maxInactiveInterval.isNegative()?false:now.minus(this.maxInactiveInterval).compareTo(this.lastAccessedTime) >= 0;
}

可见是在创建session的时候设置两个时间,

lastAccessedTime
maxInactiveInterval

如果 当前时间 - maxInactiveInterval > lastAccessedTime 就会认为session过期,设置的方法:

@EnableRedisHttpSession(maxInactiveIntervalInSeconds=2000)

【原创】大叔问题定位分享(35)spring中session失效时间的更多相关文章

  1. 关于Flask-Login中session失效时间的处理

    最近需要使用Python开发web系统,主要用到的框架就是Flask,前端使用Jinja2模板引擎和Bootstrap,web容器使用Cherrypy,其中关于Login管理的使用了Flask-Log ...

  2. 【原创】大叔问题定位分享(27)spark中rdd.cache

    spark 2.1.1 spark应用中有一些task非常慢,持续10个小时,有一个task日志如下: 2019-01-24 21:38:56,024 [dispatcher-event-loop-2 ...

  3. 【原创】大叔问题定位分享(11)Spark中对大表子查询加limit为什么会报Broadcast超时错误

    当两个表需要join时,如果一个是大表,一个是小表,正常的map-reduce流程需要shuffle,这会导致大表数据在节点间网络传输,常见的优化方式是将小表读到内存中并广播到大表处理,避免shuff ...

  4. 【原创】大叔问题定位分享(7)Spark任务中Job进度卡住不动

    Spark2.1.1 最近运行spark任务时会发现任务经常运行很久,具体job如下: Job Id  ▾ Description Submitted Duration Stages: Succeed ...

  5. 【原创】大叔问题定位分享(36)openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil

    openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil This function returns nil if the request ...

  6. 【原创】大叔问题定位分享(34)Spring的RestTemplate请求json数据后内容被修改

    先看代码 org.springframework.web.client.RestTemplate public RestTemplate() { this.messageConverters = ne ...

  7. 【原创】大叔问题定位分享(3)Kafka集群broker进程逐个报错退出

    kafka0.8.1 一 问题现象 生产环境kafka服务器134.135.136分别在10月11号.10月13号挂掉: 134日志 [2014-10-13 16:45:41,902] FATAL [ ...

  8. 【原创】大叔问题定位分享(28)openssh升级到7.4之后ssh跳转异常

    服务器集群之间忽然ssh跳转不通 # ssh 192.168.0.1The authenticity of host '192.168.0.1 (192.168.0.1)' can't be esta ...

  9. 【原创】大叔问题定位分享(6)Dubbo monitor服务iowait高,负载高

    一 问题 Dubbo monitor所在服务器状态异常,iowait一直很高,load也一直很高,监控如下: iowait如图: load如图: 二 分析 通过iotop命令可以查看当前系统中磁盘io ...

随机推荐

  1. 在 bat 批处理中运行多次 mvn

    在 bat 中运行 mvn 命令会出现这种情况,构建命令执行完成后会停留在的 mvn.bat 中,必需手工输入 exit 后,才会回到原来的脚本中继续运行.这是怎么回事? 到 maven 的安装目录下 ...

  2. Win10蓝牙鼠标老是断连卡顿的解决方法

    一直用一个微软家的蓝牙鼠标,饱受鼠标卡顿困扰,今天找到了一个解决方案,用了下,效果显著.具体操作见下文. 原文地址:https://jingyan.baidu.com/article/c85b7a64 ...

  3. python之scrapy的FormRequest模拟POST表单自动登陆

    1.FormRequest表单实现自动登陆 # -*- coding: utf-8 -*- import scrapy import re class GithubSpider(scrapy.Spid ...

  4. golang 中国代理

    vim /etc/profile export GO11MODULE=onexport GO111MODULE=onexport GOPROXY=https://goproxy.io source / ...

  5. k8s中ipvs和iptables选择

    k8s 1.11.0在 centos7上不行 1.11.1之后就可以了

  6. HTML基础知识自学教程

    HTML 是用来描述网页的一套标记标签,是我们在web前端开发中的基础.下面PHP程序员雷雪松主要结合自己的经验给大家分享下HTML的基础知识,以及在自学过程中一些比较常用的和重要的HTML知识点. ...

  7. zabbix3.0升级到4.0

    升级步鄹: 3.0->3.2 1.停服务 service zabbix-server stop 2.备份配置文件 #cp /etc/zabbix/zabbix_server.conf /data ...

  8. 【HANA系列】SAP HANA SQL去除字符串空格

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL去除字符 ...

  9. django 之(一) --- DjangoRestFormwork

    接口概念 IOP:面向接口编程,不再关注具体的实现:只关注输入.输出. http://www.ruanyifeng.com/blog/2018/10/restful-api-best-practice ...

  10. 李宏毅 Gradient Descent Demo 代码讲解

    何为梯度下降,直白点就是,链式求导法则,不断更新变量值. 这里讲解的代码为李宏毅老师机器学习课程中 class 4 回归展示 中的代码demo   Loss函数 python代码如下 import n ...