2.0版本以下设置session超时时间

1.  springboot 2.0版本以下配置session超时

1.1 application.properties配置文件: spring.session.store-type=none

1.2 引入 spring-boot和spring-session 2个依赖包


<!--session管理-->

<dependency>
<groupId>org.springframework.session</groupId>

<artifactId>spring-session</artifactId>

<version>1.3.2.RELEASE</version>

</dependency>

<!--引入配置-->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot</artifactId>

<version>1.5.4.RELEASE</version>

</dependency>

1.3在springboot启动类注入以下bean对象

package com.sinosoft.session;

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;
import java.util.concurrent.TimeUnit;
@SpringBootApplication
public class SessionApplication {
public static void main(String[] args) {
SpringApplication.run(SessionApplication.class, args
);
}
@Bean
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() {
return new EmbeddedServletContainerCustomizer() {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
//设置session超时时间为1分钟
container.setSessionTimeout(1, TimeUnit.MINUTES);
}
};
}
}

2.添加session管理器和监听器

package com.sinosoft.session.server;

import java.util.HashMap;

import javax.servlet.http.HttpSession;

/**

* Created by lijunming

* on date 2018-09-20

* session管理器

* time 20:01

*/

public class MySessionContext {

private static HashMap mymap = new HashMap();

public static synchronized void AddSession(HttpSession session) {

if (session != null) {

mymap.put(session.getId(), session);

}

}

public static synchronized void DelSession(HttpSession session) {

if (session != null) {

mymap.remove(session.getId());

}

}

public static synchronized HttpSession getSession(String session_id) {

if (session_id == null)

return null;

return (HttpSession) mymap.get(session_id);

}

}

package com.sinosoft.session.server;

import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;

import javax.servlet.http.HttpSessionEvent;

import javax.servlet.http.HttpSessionListener;

/**

* Created by lijunming

* on date 2018-09-20

* session监听器

* time 20:02

*/

@Component

public class MySessionListener implements HttpSessionListener {

@Override

public void sessionCreated(HttpSessionEvent httpSessionEvent) {

System.out.println("session正在創建");

MySessionContext.AddSession(httpSessionEvent.getSession());

}

@Override

public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {

HttpSession session = httpSessionEvent.getSession();

System.out.println("session注銷中");

MySessionContext.DelSession(session);

}

}

https://blog.csdn.net/ming19951224/article/details/82792401

springboot设置session超时和session监听的更多相关文章

  1. Spring session(redis存储方式)监听导致创建大量redisMessageListenerContailner-X线程

    待解决的问题 Spring session(redis存储方式)监听导致创建大量redisMessageListenerContailner-X线程 解决办法 为spring session添加spr ...

  2. springboot设置接口超时

    springboot 设置接口超时 1.配置文件 application.properties中加了,意思是设置超时时间为20000ms即20s, spring.mvc.async.request-t ...

  3. springBoot高级:自动配置分析,事件监听,启动流程分析,监控,部署

    知识点梳理 课堂讲义 02-SpringBoot自动配置-@Conditional使用 Condition是Spring4.0后引入的条件化配置接口,通过实现Condition接口可以完成有条件的加载 ...

  4. SpringBoot整合redis实现过期key监听事件

    Spring整合redis实现key过期事件监听:https://www.cnblogs.com/pxblog/p/13969375.html 可以用于简单的过期订单取消支付.7天自动收货场景中 1. ...

  5. EditText设置文字改变时的监听

    textWatcher = new TextChangeWatcher(); etQuerryInfo.addTextChangedListener(textWatcher); /** * 文字改变类 ...

  6. SpringBoot 对IBM MQ进行数据监听接收以及数据发送

    一.需求介绍 后端使用Spring Boot2.0框架,要实现IBM MQ的实时数据JMS监听接收处理,并形成回执通过MQ队列发送. 二.引入依赖jar包 <dependency> < ...

  7. echarts 与 百度地图bmap结合系列: 如何设置地图缩放级别和监听缩放事件

    简单的demo: // ehcarts 的实例对象 this.myChart = echarts.init(el) // ehcarts加载完成事件 this.myChart.on('finished ...

  8. angular设置全局变量,可修改监听变量

    创建service.module.ts import { NgModule, ModuleWithProviders } from '@angular/core'; import { SomeShar ...

  9. UIView中UIButton设置监听

    红色框框是一个uibutton _priceValueLabel是他的父视图, 必须要把button的父视图设置userInteractionEnabled = YES, button的 监听才会生效 ...

随机推荐

  1. java关于字符串的一些实用操作工具类方法

    package cn.edu.stdu; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Se ...

  2. Flask 系列之 LoginManager

    说明 操作系统:Windows 10 Python 版本:3.7x 虚拟环境管理器:virtualenv 代码编辑器:VS Code 实验目标 通过使用 flask-login 进行会话管理的相关操作 ...

  3. 10个常见的JavaScript BUG

    译者按: 安全起见,在开发中我基本不用==. 原文: 10 COMMON JAVASCRIPT BUGS AND HOW TO AVOID THEM 译者: Fundebug 为了保证可读性,本文采用 ...

  4. select&epoll

    内核空间和用户空间 现在操作系统都是采用虚拟存储器,那么对 32 位操作系统而言,它的寻址空间(虚拟地址空间,或叫线性地址空间)为 4G(2的32次方).也就是说一个进程的最大地址空间为 4G.操作系 ...

  5. layui table 表格模板按钮实例

    这是个是全部的jsp 页面: <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8& ...

  6. 洛谷P4590 [TJOI2018]游园会(状压dp LCS)

    题意 题目链接 Sol 这个题可能是TJOI2018唯一的非模板题了吧.. 考虑LCS的转移方程, \[f[i][j] = max(f[i - 1][j], f[i][j - 1], f[i - 1] ...

  7. 2018-08-14 中文代码之Spring Boot实现简单REST服务

    最终目标详见: 参考MSDN,试搞.NET类库标识符的翻译版 · Issue #54 · program-in-chinese/overview 此文仅为技术探索+原型搭建的第一小步. 源码库: 演示 ...

  8. Dynamics 365 Online-Relevance Search

    区别于Quick Find,以及Full-Text Quick Find,Dynamics 365 Online有了一个特有的Search功能:Relevance Search.至于为什么是Onlin ...

  9. XRecyclerView上拉刷新下拉加载

    效果图: 首先要添加依赖: //xrecyclerviewimplementation 'com.jcodecraeer:xrecyclerview:1.3.2'//Gsonimplementatio ...

  10. JPTabBar 详细介绍

    一个强大的TabBar,实现市面上APP基本上所拥有的功能,代码简单构造容易!只需不足5行代码就把基本的界面搭建出来了 附上效果图: 主要功能特色: 多种Tab切换的动画效果 实现底部导航中间按钮凸出 ...