场景:使用redis存储shiro的session
当根据sessionId从redis中获取session对象时应返回null
try {
if (null != sessionId) {
byte[] bytes = robertRedisClient.get(redisSerializer.serialize(SHIRO_SESSION + sessionId.toString()));
if (1 > bytes.length) {
return null;
}
return (Session) redisSerializer.deserialize(bytes);
}
return null;
} catch (Exception e) {
log.error("获取shiro的session时发生异常,异常详细信息:\n {}", ExceptionUtils.getStackTrace(e));
return null;
}
问题:1、后台日志上可以看到nullpointexception,可也有新session创建的日志输出
2019-05-06 16:41:46.583 [XNIO-1 task-6] ERROR- com.robert.auth.session.RedisSessionDao - 获取shiro的session时发生异常,异常详细信息:
java.lang.NullPointerException
at com.robert.auth.session.RedisSessionDao.doReadSession(RedisSessionDao.java:54)
at org.apache.shiro.session.mgt.eis.AbstractSessionDAO.readSession(AbstractSessionDAO.java:168)
2019-05-06 16:41:46.583 [XNIO-1 task-6] DEBUG- com.robert.auth.session.RedisSessionDao - 新增一个session:3dfe4f26-ddb2-4b1e-9fc0-fa772cd60dd8
2019-05-06 16:41:46.583 [XNIO-1 task-6] DEBUG- com.robert.auth.session.RedisSessionDao - 创建session的host:192.168.0.221,session主键:3dfe4f26-ddb2-4b1e-9fc0-fa772cd60dd8,最后访问时间:Mon May 06 16:41:46 CST 2019
2019-05-06 16:41:46.584 [XNIO-1 task-6] DEBUG- com.robert.auth.redis.RobertRedisClient - 向redis中写数据:key-shiro-session:3dfe4f26-ddb2-4b1e-9fc0-fa772cd60dd8,value-...,timeout-1800
2019-05-06 16:41:46.585 [XNIO-1 task-6] DEBUG- com.robert.auth.session.RedisSessionDao - 更新shiro session :3dfe4f26-ddb2-4b1e-9fc0-fa772cd60dd8
2019-05-06 16:41:46.585 [XNIO-1 task-6] DEBUG- com.robert.auth.session.RedisSessionDao - 创建session的host:192.168.0.221,session主键:3dfe4f26-ddb2-4b1e-9fc0-fa772cd60dd8,最后访问时间:Mon May 06 16:41:46 CST 2019
2019-05-06 16:41:46.585 [XNIO-1 task-6] DEBUG- com.robert.auth.redis.RobertRedisClient - 向redis中写数据:key-shiro-session:3dfe4f26-ddb2-4b1e-9fc0-fa772cd60dd8,value-...,timeout-1800
2、客户端获取不到请求响应