session超时处理
demo的application中加入超时配置
# 默认30分钟 server.servlet.session.timeout=30m
server.servlet.session.timeout= 10s
但是当我们登录上去发下session的超时时间远超过了10s
原因
看 TomcatEmbeddedServletContainerFactory 类
但找不到这个类
Spring Boot 2中缺少TomcatEmbeddedServletContainerFactory(TomcatEmbeddedServletContainerFactory is missing in Spring Boot 2)
为了支持反应用例,嵌入式容器
包结构已经被非常广泛地重构。
EmbeddedServletContainer已重命名为WebServer,
org.springframework.boot.context.embedded包已重新定位
到org.springframework.boot.web.server。相应地,
EmbeddedServletContainerCustomizer已重命名为
WebServerFactoryCustomizer。
例如,如果您使用TomcatEmbeddedServletContainerFactory自定义嵌入式Tomcat容器
回调接口,
你现在应该使用TomcatServletWebServerFactory,如果你使用
一个EmbeddedServletContainerCustomizer bean,你现在应该使用
WebServerFactoryCustomizer bean。
看TomcatServletWebServerFactory类
private void configureSession(Context context) {
long sessionTimeout = this.getSessionTimeoutInMinutes();//以分钟为单位读取超时时间
context.setSessionTimeout((int)sessionTimeout);//超时时间取整,则说明超时时间最低为1分钟
Boolean httpOnly = this.getSession().getCookie().getHttpOnly();
if (httpOnly != null) {
context.setUseHttpOnly(httpOnly);
}
if (this.getSession().isPersistent()) {
Manager manager = context.