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)

最新文章

  1. SQL 表连接查询出现重复列,由此理清LEFT JOIN、INNER JOIN的区别
  2. An error occurred while collecting items to be installed
  3. Coursera Machine Learning : Regression 多元回归
  4. 【转】CV_EXPORT定义的作用,lib及dll的区别
  5. SU Demos-05Sorting Traces-02Demos
  6. WOJ-1097
  7. (转)解决ScrollView嵌套ListView或者GridView导致只显示一行的方法
  8. windows C 与 linux C区别?
  9. 全面剖析XML和JSON
  10. 运行一个Hadoop Job所需要指定的属性
  11. Java调用Lua(转)
  12. 转 layout_weight体验(实现按比例显示)
  13. uoj#38. 【清华集训2014】奇数国【欧拉函数】
  14. 服务器开发之CGI后门
  15. Kafka最佳实践
  16. Pytorch中torch.autograd ---backward函数的使用方法详细解析,具体例子分析
  17. 0.5px border 实现方案
  18. c++builder 字节 编码 转换大全 String TBytes byte
  19. 【[HNOI2010]弹飞绵羊】
  20. 【Excle数据透视】多列分别分类计数

热门文章

  1. Activity的生命周期是谁调用的?
  2. TreeView 三种状态 没多大变化 只是增加了很多函数以方便调用
  3. docker 管理应用程序数据和网络管理
  4. 一个Action中,可以写多个类似的业务控制方法
  5. EclipseADT编写单元测试代码的步骤
  6. zabbix通过SDK和API获取阿里云RDS的监控数据
  7. elk报错解决
  8. ValueError: Object arrays cannot be loaded when allow_pickle=False
  9. Java学习笔记-Java中的常用类
  10. 第10课.c++的新成员