Shiro配置Session检测时Quartz版本冲突
项目背景: shiro 1.3 + quartz 2.x
2018-9-11 22:20:35补充:
经过测试,本人发现 ,通过实现 org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler 同样能解决相关问题,具体原因正在查找.
利用该类进行实现则不必自定义了.完整配置如下:(异同部分已高亮)
<!-- 配置session的定时验证检测程序类,以让无效的session释放 -->
<bean id="sessionValidationScheduler"
class="org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler">
<!-- 设置session的失效扫描间隔,单位为毫秒 -->
<property name="interval" value="1800000"/>
<!-- 随后还需要定义有一个会话管理器的程序类的引用 -->
<property name="sessionManager" ref="sessionManager"/>
</bean>
如果上面的方式不能解决问题,那么可以选择下面这种方式:
-------------------------------------------------------------------------华丽的分割线--------------------------------------------------------------------------------------------
期初的session会话配置如下:
<bean id="sessionValidationScheduler"
class="org.apache.shiro.session.mgt.quartz.QuartzSessionValidationScheduler">
<!-- 设置session的失效扫描间隔,单位为毫秒 -->
<property name="sessionValidationInterval" value="1800000"/>
<!-- 随后还需要定义有一个会话管理器的程序类的引用 -->
<property name="sessionManager" ref="sessionManager"/>
</bean>
class="org.apache.shiro.session.mgt.quartz.QuartzSessionValidationScheduler" 默认shiro使用的是这个来编译,但是quartz2.x之后实现方式变了,所以需要自定义实现:自定义实现类如下:
代码是从网上找的,也试过没啥问题.直接复制就好,不需要做修改.
package xxxxx;
import org.apache.shiro.session.mgt.SessionValidationScheduler;
import org.apache.shiro.session.mgt.ValidatingSessionManager;
import org.apache.shiro.session.mgt.quartz.QuartzSessionValidationJob;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; public class Quartz2SessionValidationScheduler implements
SessionValidationScheduler {
public static final long DEFAULT_SESSION_VALIDATION_INTERVAL = 3600000L;
private static final String JOB_NAME = "SessionValidationJob";
private static final Logger log = LoggerFactory
.getLogger(Quartz2SessionValidationScheduler.class);
private Scheduler scheduler;
private boolean schedulerImplicitlyCreated = false; private boolean enabled = false;
private ValidatingSessionManager sessionManager;
private long sessionValidationInterval = 3600000L; public Quartz2SessionValidationScheduler() {
} public Quartz2SessionValidationScheduler(
ValidatingSessionManager sessionManager) {
this.sessionManager = sessionManager;
} protected Scheduler getScheduler() throws SchedulerException {
if (this.scheduler == null) {
this.scheduler = StdSchedulerFactory.getDefaultScheduler();
this.schedulerImplicitlyCreated = true;
}
return this.scheduler;
} public void setScheduler(Scheduler scheduler) {
this.scheduler = scheduler;
} public void setSessionManager(ValidatingSessionManager sessionManager) {
this.sessionManager = sessionManager;
} public boolean isEnabled() {
return this.enabled;
} public void setSessionValidationInterval(long sessionValidationInterval) {
this.sessionValidationInterval = sessionValidationInterval;
} public void enableSessionValidation() {
if (log.isDebugEnabled()) {
log.debug("Scheduling session validation job using Quartz with session validation interval of ["
+ this.sessionValidationInterval + "]ms...");
} try {
SimpleTrigger trigger = TriggerBuilder
.newTrigger()
.startNow()
.withIdentity(JOB_NAME, "DEFAULT")
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMilliseconds(
sessionValidationInterval)).build(); JobDetail detail = JobBuilder
.newJob(QuartzSessionValidationJob.class)
.withIdentity(JOB_NAME, "DEFAULT").build();
detail.getJobDataMap().put("sessionManager", this.sessionManager);
Scheduler scheduler = getScheduler(); scheduler.scheduleJob(detail, trigger);
if (this.schedulerImplicitlyCreated) {
scheduler.start();
if (log.isDebugEnabled()) {
log.debug("Successfully started implicitly created Quartz Scheduler instance.");
}
}
this.enabled = true; if (log.isDebugEnabled())
log.debug("Session validation job successfully scheduled with Quartz.");
} catch (SchedulerException e) {
if (log.isErrorEnabled())
log.error(
"Error starting the Quartz session validation job. Session validation may not occur.",
e);
}
} public void disableSessionValidation() {
if (log.isDebugEnabled()) {
log.debug("Stopping Quartz session validation job...");
}
Scheduler scheduler;
try {
scheduler = getScheduler();
if (scheduler == null) {
if (log.isWarnEnabled()) {
log.warn("getScheduler() method returned a null Quartz scheduler, which is unexpected. Please check your configuration and/or implementation. Returning quietly since there is no validation job to remove (scheduler does not exist).");
} return;
}
} catch (SchedulerException e) {
if (log.isWarnEnabled()) {
log.warn(
"Unable to acquire Quartz Scheduler. Ignoring and returning (already stopped?)",
e);
}
return;
}
try {
scheduler.unscheduleJob(new TriggerKey("SessionValidationJob",
"DEFAULT"));
if (log.isDebugEnabled())
log.debug("Quartz session validation job stopped successfully.");
} catch (SchedulerException e) {
if (log.isDebugEnabled()) {
log.debug(
"Could not cleanly remove SessionValidationJob from Quartz scheduler. Ignoring and stopping.",
e);
} } this.enabled = false; if (this.schedulerImplicitlyCreated)
try {
scheduler.shutdown();
} catch (SchedulerException e) {
if (log.isWarnEnabled())
log.warn(
"Unable to cleanly shutdown implicitly created Quartz Scheduler instance.",
e);
} finally {
setScheduler(null);
this.schedulerImplicitlyCreated = false;
}
}
}
复制完之后修改配置:
<!-- 配置session的定时验证检测程序类,以让无效的session释放 -->
<bean id="sessionValidationScheduler"
class="xxxxx.Quartz2SessionValidationScheduler">
<!-- 设置session的失效扫描间隔,单位为毫秒 -->
<!--shiro使用的是1.6的quartz,现程序已使用了quartz 2.x,1.6和2.x的实现方式不一样,所以这里需要自定义重新实现-->
<property name="sessionValidationInterval" value="1800000"/>
<!-- 随后还需要定义有一个会话管理器的程序类的引用 -->
<property name="sessionManager" ref="sessionManager"/>
</bean>
Shiro配置Session检测时Quartz版本冲突的更多相关文章
- 解决shiro和quartz2 版本冲突问题
修改build.gradle compile ("org.quartz-scheduler:quartz:2.2.3") compile ("org.apache.s ...
- Shiro配置cookie以及共享Session和Session失效问题
首先我们看Shiro的会话管理器的配置 <!-- shiro会话管理 --> <!-- 即用户登录后就是一次会话,在没有退出之前,它的所有信息都在会话中:会话可以是普通 JavaSE ...
- svn -- 数据备份,版本回退,版本冲突,多仓库配置
数据备份 差异存储法: 版本回退 版本冲突 原理图: 解决办法: 三种方案: 1)合理分配项目开发模块 wangcai:文章,邮件,会员 xiaoqiang:静态化,缓存,前台 2)合理分配项目开发时 ...
- Spring Shiro配置第三方SSO客户端登录
经过实践的Shiro配置,利用 sSOInterceptor 进行sso登录拦截 配置 @Configuration public class ShiroConfiguration extends B ...
- maven exclusion 解决maven传递依赖中的版本冲突
传递依赖是maven最有特色的.最为方便的优点之一,可以省了很多配置.如a 依赖 b,b 依赖c 默认 a也会依赖 c.但是也会带来隐患,如版本冲突.当然maven也考虑到解决办法,可以使用exclu ...
- Jetty集群配置Session存储到MySQL、MongoDB
在Web开发中,Session表示HTTP服务器与客户端(例如浏览器)的“会话”,每个客户端会有其对应的Session保存在服务器端,通常用来保存和客户端关联的一些信息,例如是否登录.购物车等. Se ...
- Java Gradle入门指南之依赖管理(添加依赖、仓库、版本冲突)
开发任何软件,如何管理依赖是一道绕不过去的坎,软件开发过程中,我们往往会使用这样那样的第三方库,这个时候,一个好的依赖管理就显得尤为重要了.作为一个自动构建工作,Gradle对依赖管理有着很好 ...
- 【转载】PHP.INI配置:Session配置详细说明教程
网上有很多PHP.INI文件配置的中文说明,但是对于PHP初学者来说在进行PHP运行环境搭建配置时还是容易一头雾水,今天换一种角度来分享如何进行php.ini配置,以求达到解决实际问题的效果,开篇以P ...
- 解决版本冲突-使用SVN主干与分支功能
解决版本冲突-使用SVN主干与分支功能 1 前言 大多数产品开发存在这样一个生命周期:编码.测试.发布,然后不断重复.通常是这样的开发步骤: 1) 开发人员开发完毕某一版本(如版本A)功能后, ...
随机推荐
- chrome打开Axure Rp导出的html文件提示需要安装Axure Rp插件解决办法
1.确保chrome安装了Axure Rp扩展插件,如果按照页面的提示去下载,但是打不开的话就是被墙了,贴上科学的上网梯子https://www.lanzous.com/i7i0wuh,直接下载打开就 ...
- 最短路径——BFS算法
最短路径--BFS算法 单源最短路径问题 每对顶点间的最短路径 BFS求无权图的单源最短路径 bool visited[MAX_VERTEX_NUM]; //访问标记数组 //广度优先遍历 void ...
- MySQL PXC集群安装配置
1.关闭防火墙 [root@node04 ~]#systemctl disable firewalld [root@node04 ~]#systemctl stop firewalld [root@n ...
- 安卓和ios的app证书过期的相关问题汇总
一,ios的APP的发布流程请见:ios的APP的发布流程 http://www.jianshu.com/p/b1b77d804254 这篇文章写得很好很全面 二,app证书过期了怎么办: IOS的情 ...
- ES6中的Promise和Generator详解
目录 简介 Promise 什么是Promise Promise的特点 Promise的优点 Promise的缺点 Promise的用法 Promise的执行顺序 Promise.prototype. ...
- vue第二单元(webpack的配置-学习webpack的常用配置)
第二单元(webpack的配置-学习webpack的常用配置) #课程目标 掌握webpack的常用配置 掌握如何根据实际的需求修改webpack的对应配置 了解webpack-dev-server的 ...
- Shell-匹配行及date日期转换
#将指定字符串转化为从1970年1月1日到现在的秒数. date -d '20170506' "+%s" #将1970年1月1日到现在累计的秒数转化为日期 date -d @149 ...
- Spark性能调优篇八之shuffle调优
1 task的内存缓冲调节参数 2 reduce端聚合内存占比 spark.shuffle.file.buffer map task的内存缓冲调节参数,默认是3 ...
- matplotlib的学习7-tick能见度
import matplotlib.pyplot as plt import numpy as np ''' 当图片中的内容较多,相互遮盖时,我们可以通过设置相关内容的透明度来使图片更易于观察,也即是 ...
- C++模板元编程----快速排序
目录 目录 简介 实现 数据结构定义 在数组前添加一个元素 判断 分堆 合并 快速排序的实现 总结 简介 上一篇使用C++模板模板实现了一个选择排序.这一次,更进一步的,实现了一个快速排序算法.关于快 ...