spring boot设置session超时时间
springboot1.x设置session超时时间:
按优先级高到低说:
第一种:
spring boot 启动类里面:
1 package com.mycenter; 2 3 import org.mybatis.spring.annotation.MapperScan; 4 import org.springframework.boot.SpringApplication; 5 import org.springframework.boot.autoconfigure.SpringBootApplication; 6 import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; 7 import org.springframework.boot.web.servlet.ServletComponentScan; 8 import org.springframework.context.annotation.Bean; 9 10 @SpringBootApplication 11 @MapperScan(value = "com.mycenter.mapper") 12 @ServletComponentScan 13 public class MycenterApplication { 14 15 public static void main(String[] args) { 16 SpringApplication.run(MycenterApplication.class, args); 17 } 18 19 20 @Bean 21 public EmbeddedServletContainerCustomizer containerCustomizer(){ 22 return container -> { 23 container.setSessionTimeout(7200);/*单位为S*/ 24 }; 25 } 26 }
第二种:
暂时用这两种。
springboot2.x设置session超时时间:
springboot2.x设置session时间使用的是java8新增的duration类,需要按照规范书写,例:
Duration转换字符串方式,默认为正,负以-开头,紧接着P,(字母不区分大小写)D :天 T:天和小时之间的分隔符 H :小时 M:分钟 S:秒 每个单位都必须是数字,且时分秒顺序不能乱。例:PT2H就是2个小时,7200秒。