问题

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版本

image-20210721141755093

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 创建逻辑

image-20210721141126851

image-20210721141142380

image-20210721141202065

image-20210721141225774

问题出现点

当创建完默认的scheduler 后会执行一次 run方法。

image-20210721141334244

继续跟踪代码

image-20210721141902921

发现 此处有异常,但是异常并未被捕获,导致线程中断。

网上百度此异常 说是,jedis版本不一致导致。

解决方案

查看shiro-redis pom文件jedis的版本号。

image-20210721142036883

发现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 方法不调用的问题, 此方法是通过上面的定时任务提醒来进行触发的。

image-20210721153608444

由于,redis 和ehcache 本身设置了过期时间,过期之后 session 变从 redis 后者ehcache 里面删除,因此 onExpiration 过期之后此方法 永远不会被调用到。

posted on 2021-07-21 14:27  XIN1024  阅读(160)  评论(0编辑  收藏  举报