springboot设置session超时和session监听
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管理-->
<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;
2.添加session管理器和监听器
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);
}
}
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监听的更多相关文章
- Spring session(redis存储方式)监听导致创建大量redisMessageListenerContailner-X线程
待解决的问题 Spring session(redis存储方式)监听导致创建大量redisMessageListenerContailner-X线程 解决办法 为spring session添加spr ...
- springboot设置接口超时
springboot 设置接口超时 1.配置文件 application.properties中加了,意思是设置超时时间为20000ms即20s, spring.mvc.async.request-t ...
- springBoot高级:自动配置分析,事件监听,启动流程分析,监控,部署
知识点梳理 课堂讲义 02-SpringBoot自动配置-@Conditional使用 Condition是Spring4.0后引入的条件化配置接口,通过实现Condition接口可以完成有条件的加载 ...
- SpringBoot整合redis实现过期key监听事件
Spring整合redis实现key过期事件监听:https://www.cnblogs.com/pxblog/p/13969375.html 可以用于简单的过期订单取消支付.7天自动收货场景中 1. ...
- EditText设置文字改变时的监听
textWatcher = new TextChangeWatcher(); etQuerryInfo.addTextChangedListener(textWatcher); /** * 文字改变类 ...
- SpringBoot 对IBM MQ进行数据监听接收以及数据发送
一.需求介绍 后端使用Spring Boot2.0框架,要实现IBM MQ的实时数据JMS监听接收处理,并形成回执通过MQ队列发送. 二.引入依赖jar包 <dependency> < ...
- echarts 与 百度地图bmap结合系列: 如何设置地图缩放级别和监听缩放事件
简单的demo: // ehcarts 的实例对象 this.myChart = echarts.init(el) // ehcarts加载完成事件 this.myChart.on('finished ...
- angular设置全局变量,可修改监听变量
创建service.module.ts import { NgModule, ModuleWithProviders } from '@angular/core'; import { SomeShar ...
- UIView中UIButton设置监听
红色框框是一个uibutton _priceValueLabel是他的父视图, 必须要把button的父视图设置userInteractionEnabled = YES, button的 监听才会生效 ...
随机推荐
- SpringBoot 之Thymeleaf模板.
一.前言 Thymeleaf 的出现是为了取代 JSP,虽然 JSP 存在了很长时间,并在 Java Web 开发中无处不在,但是它也存在一些缺陷: 1.JSP 最明显的问题在于它看起来像HTML或X ...
- MySQL主从 常见的错误及解决方案
一.错误日志解析: (1) [ERROR]1452:无法在外键的表插入参考主键没有的数据 1452:无法在外键的表插入或更新参考主键没有的数据.由于item_discovery.itemid字段(外键 ...
- awesome python 中文版 相见恨晚!
awesome python 中文版 相见恨晚! https://www.zhihu.com/question/24590883 这篇知乎厉害了!一定要学习! 作者:知乎用户链接:https:// ...
- [转载]Web Service到底是什么
转自:http://blog.csdn.net/wooshn/article/details/8069087/ 武僧的专栏 一.序言 大家或多或少都听过WebService(Web服务),有一段时间 ...
- angular post 带参数 导出excel
原文地址:http://www.cnblogs.com/xujanus/p/5985644.html html <button class="btn btn-info" ng ...
- vue+vuecli+webapck2项目配置文件详解
1.文件结构 ├─build │ ├─build.js │ ├─check-versions.js │ ├─dev-client.js │ ├─dev-server.js │ ├─utils.js │ ...
- cf934C. A Twisty Movement(思维题)
题意 题目链接 Sol 这题最直接的维护区间以0/1结尾的LIS的方法就不说了. 其实我们可以直接考虑翻转以某个位置为中点的区间的最大值 不难发现前缀和后缀产生的贡献都是独立的,可以直接算.维护一下前 ...
- html 获取数据并发送给后端方式
一.方式一 使用ajax提交 function detailed() { var date = $("#asset_ip").text() $.ajax({ url: " ...
- springmvc 获取请求头信息
@PostMapping("/test/post") public void post(@RequestBody String params, @RequestHeader(req ...
- Django+MongoDB批量插入数据
在百万级和千万级数据级别进行插入,pymongo的insert_many()方法有着很强的优势.原因是每次使用insert_one()方法进行插入数据,都是要对数据库服务器进行一次访问,而这样的访问是 ...