使用自定义shiro Session管理 用户退出时出现StoppedSessionException 异常
//用户退出 SecurityUtils.getSubject().logout();
/** * 自定义session 管理 * 解决多次请求redis session 问题 * @author Administrator * */ public class CustomSessionManager extends DefaultWebSessionManager{ @Override protected Session retrieveSession(SessionKey sessionKey) throws UnknownSessionException { System.out.println(">>>>>>进入>>>>session>>>>>start"); Serializable sessionId = getSessionId(sessionKey); ServletRequest request=null; if(sessionId ==null ) { System.out.println(">>>>>>sessionId is null"); System.out.println(">>>>>>进入>>>>session>>>>end"); return null; } if(sessionKey instanceof WebSessionKey) { request = ((WebSessionKey) sessionKey).getServletRequest(); } //先从request中获取session 如果没有 if(request != null && sessionId != null) { Session session = (Session) request.getAttribute(sessionId.toString()); //返回不为null的session if(session != null ) { System.out.println(">>>>>>进入>>>>session>>>>end1"); return session; } } //如果request 中没有 session 则从redis中获取并保存到request Session session = super.retrieveSession(sessionKey); if(request != null && sessionId != null ) { request.setAttribute(sessionId.toString(), session); } System.out.println(">>>>>>进入>>>>session>>>>end2"); return session; } } 异常信息↓
六月 21, 2018 3:56:30 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [DispatcherServlet] in context with path [/shiro-spring] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: org.apache.shiro.session.StoppedSessionException: Session with id [77105aa0-5cf8-411a-9a4f-2f257674eb8e] has been explicitly stopped. No further interaction under this session is allowed.] with root cause org.apache.shiro.session.StoppedSessionException: Session with id [77105aa0-5cf8-411a-9a4f-2f257674eb8e] has been explicitly stopped. No further interaction under this session is allowed. at org.apache.shiro.session.mgt.SimpleSession.validate(SimpleSession.java:270) at org.apache.shiro.session.mgt.AbstractValidatingSessionManager.doValidate(AbstractValidatingSessionManager.java:186) at org.apache.shiro.session.mgt.AbstractValidatingSessionManager.validate(AbstractValidatingSessionManager.java:143) at org.apache.shiro.session.mgt.AbstractValidatingSessionManager.doGetSession(AbstractValidatingSessionManager.java:120) at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupSession(AbstractNativeSessionManager.java:148) at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupRequiredSession(AbstractNativeSessionManager.java:152) at org.apache.shiro.session.mgt.AbstractNativeSessionManager.getAttribute(AbstractNativeSessionManager.java:249)
有大佬测试过怎么解决吗????!!!!