Springboot设置session超时时间


按优先级高到低说:

第一种:

spring boot 启动类里面:

package com.mycenter;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@MapperScan(value = "com.mycenter.mapper")
@ServletComponentScan
public class MycenterApplication {

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

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer(){
        return container -> {
            container.setSessionTimeout(7200);/*单位为S*/
        };
    }
}

第二种 yml文件配置

server:
    port: 8080
    session:
        timeout: 7200


免责声明!

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



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