如果是1.5.6版本

这里 可以在application中加上bean文件

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
}

//设置session过期时间
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {

        public void customize(ConfigurableEmbeddedServletContainer container) {
            container.setSessionTimeout(7200);// 单位为S
        }
    };
}

}

在这里插入图片描述


还可以设置
application.yml

server:
port: 8081
servlet:
session:
timeout: 60s

在这里插入图片描述

@RestController
public class HelloController {

@PostMapping("test")
public Integer getTest(@RequestParam("nyy")String nn, HttpServletRequest httpServletRequest ){
    HttpSession session = httpServletRequest.getSession();
   session.setMaxInactiveInterval(60);

    int maxInactiveInterval = session.getMaxInactiveInterval();
    long lastAccessedTime = session.getLastAccessedTime();
    return maxInactiveInterval;
}

}

在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐