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. Nginx之HTTP过滤模块

    1. HTTP 过滤模块 ngx_http_not_modified_module 仅对 HTTP 头部做处理.在返回 200 成功时,根据请求中 If-Modified-Since 或者 If-Un ...

  2. react-hook设定定时器的方法

    const useInterval = (callback, delay) => { const savedCallback = useRef(); // 保存新回调 useEffect(() ...

  3. 怎么彻底关闭卸载删除Cortana小娜进程,最简单

    原文地址:https://jingyan.baidu.com/article/90bc8fc8be67bcf653640cfa.html Win10中的Cortana是微软开发的一款个人AI助理,集聊 ...

  4. C#.net winform skin 皮肤大全

    C#.net winform skin 皮肤大全 1. 东日IrisSkin IrisSkin 共有两个版本,一个是IrisSkin.dll 用于.Net Framework1.0/1.1 和Iris ...

  5. 一百:CMS系统之修改密码逻辑

    定义一个基类form,用于获取错误信息 from wtforms import Form class BaseForm(Form): def get_error(self): # a = {'aaa' ...

  6. [CDH] Process data: integrate Spark with Spring Boot

    c 一.Spark 统计计算 简单统计后写入Redis. /** * 订单统计和乘车人数统计 */ object OrderStreamingProcessor { def main(args: Ar ...

  7. RDD的cache 与 checkpoint 的区别

    问题:cache 与 checkpoint 的区别? 关于这个问题,Tathagata Das 有一段回答: There is a significant difference between cac ...

  8. Spring MVC的多视图解析器配置及与Freemarker的集成

    一.从freemarker谈起 Freemarker使用模板技术进行视图的渲染.自从看了Struts标签.Freemarker.JSTL的性能对比后,我毅然决定放弃Struts标签了!效率太差…… S ...

  9. Go项目实战:打造高并发日志采集系统(四)

    前情回顾 前文我们完成了如下目标1 项目架构整体编写2 使框架支持热更新 本节目标 在前文的框架基础上,我们1 将之前实现的日志监控功能整合到框架中.2 一个日志对应一个监控协程,当配置热更新后根据新 ...

  10. 视图push和presentViewController注意点

    presentViewController: - (void)publishClick{ NSLog(@"发布按钮被点击"); PublishViewController *pub ...