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秒。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM