欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot項(xiàng)目如何設(shè)置session的過(guò)期時(shí)間

 更新時(shí)間:2022年01月27日 08:57:40   作者:yyk的萌  
這篇文章主要介紹了springboot項(xiàng)目如何設(shè)置session的過(guò)期時(shí)間,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

這里我們只介紹springboot2.0的session時(shí)間設(shè)置

Duration轉(zhuǎn)換字符串方式,默認(rèn)為正,負(fù)以-開(kāi)頭,緊接著P,(字母不區(qū)分大小寫)D :天 T:天和小時(shí)之間的分隔符 H :小時(shí) M:分鐘 S:秒 每個(gè)單位都必須是數(shù)字,且時(shí)分秒順序不能亂。

例如PT10M,就是設(shè)置為10分鐘,

下面這種方式是設(shè)置24小時(shí)的

在這里插入圖片描述

錯(cuò)誤的設(shè)置是下面這種方式,這種是不起效果的

server.servlet.session.timeout=30s

或者使用第二種方式

session1.setMaxInactiveInterval(60*60);//設(shè)置session一小時(shí)后失效

springboot設(shè)置session失效的幾種方式

如果是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 {undefined
public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
}
//設(shè)置session過(guò)期時(shí)間
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        public void customize(ConfigurableEmbeddedServletContainer container) {
            container.setSessionTimeout(7200);// 單位為S
        }
    };
}
}

在這里插入圖片描述

第二個(gè)

還可以設(shè)置

application.yml

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

在這里插入圖片描述

第三個(gè)

@RestController
public class HelloController {undefined
@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;
}
}

在這里插入圖片描述

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論