spring boot 2.0以后,session超时在application.properties设置如下:
server.servlet.session.timeout=120
由于spring boot设置的session超时时间单位是秒,而spring boot的session超时时间最终要将其赋值给spring boot内置的tomcat,而tomcat的默认session超时时间单位是分(钟),因此,spring boot的session超时时间设置需要是60的倍数,即tomcat的超时时间单位是整数;如果不是60的倍数,tomcat会自动进行转化,
比如:
spring boot设置session超时时间是30秒,tomcat会转成是1分钟,默认是60秒。
1)程序中要获取session的超时时间,获取方式如下:
request.getSession().getMaxInactiveInterval();
2)session有效持续到销毁的时间点方法为:
new Date(request.getSession().getLastAccessedTime());
参考:
spring boot的session超时问题详解;
https://www.cnblogs.com/ergexy/p/9684933.html