/** * 重写sessonManager * 解决shiro多次从redis读取session的问题 */ public class CustomSessionManager extends DefaultWebSessionManager { @Override protected Session retrieveSession(SessionKey sessionKey) throws UnknownSessionException { Serializable sessionId = getSessionId(sessionKey); ServletRequest request = null; if(sessionKey instanceof WebSessionKey) { request = ((WebSessionKey) sessionKey).getServletRequest(); } if(request!=null&& sessionId !=null) { Session session = (Session)request.getAttribute(sessionId.toString()); if(session !=null && sessionId !=null) { return session; } } Session session = super.retrieveSession(sessionKey); if(request!=null && sessionId !=null) { request.setAttribute(sessionId.toString(), session); } return session; } }