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