问题 redis 抛出异常: redis.clients.jedis.ScanResult.getStringCursor()Ljava/lang/String;Method threw 'java.lang.NoSuchMethodError' exception. 说明 spring-boot 版本 parent groupIdorg.springframework.boot/groupId artifactIdspring-b
问题
redis 抛出异常:
redis.clients.jedis.ScanResult.getStringCursor()Ljava/lang/String; Method threw 'java.lang.NoSuchMethodError' exception.
说明
spring-boot 版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
shiro-redis版本
<dependency> <groupId>org.crazycake</groupId> <artifactId>shiro-redis</artifactId> <version>3.2.3</version> </dependency>
jedis版本

shiro设置定时检测session失效
shiro配置session失效时间,没有引用shiro-quartz ,采用默认的
ExecutorServiceSessionValidationScheduler
shiro 配置
@Bean
public SessionManager sessionManager(SimpleCookie simpleCookie, SessionDAO sessionDAO) {
logger.debug("安全框架配置:开始sessionManager配置");
SkySessionManager skySessionManager = new SkySessionManager();
skySessionManager.setSessionDAO(sessionDAO);
skySessionManager.setSessionIdCookie(simpleCookie);
// 开启cookie
skySessionManager.setSessionIdCookieEnabled(true);
// session 失效删除session
skySessionManager.setDeleteInvalidSessions(true);
// 定期检查 失效的 session
skySessionManager.setSessionValidationInterval(10000);
// 开启 schedule
skySessionManager.setSessionValidationSchedulerEnabled(true);
skySessionManager.setSessionListeners(Collections.singletonList(new SkySessionListener()));
logger.debug("安全框架配置:结束sessionManager配置");
return skySessionManager;
}
shiro schedule 创建逻辑




问题出现点
当创建完默认的scheduler 后会执行一次 run方法。

继续跟踪代码

发现 此处有异常,但是异常并未被捕获,导致线程中断。
网上百度此异常 说是,jedis版本不一致导致。
解决方案
查看shiro-redis pom文件jedis的版本号。

发现jedis版本号为2.9.0
将jedis 2.9.0 集成进项目:
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency>
至此问题解决。
@Override public void onExpiration(Session session)
onExpiration 方法不调用的问题, 此方法是通过上面的定时任务提醒来进行触发的。

由于,redis 和ehcache 本身设置了过期时间,过期之后 session 变从 redis 后者ehcache 里面删除,因此 onExpiration 过期之后此方法 永远不会被调用到。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持自由互联。
