多次请求断点发现频繁调用了doReadSession方法。
@Override
protected Session doReadSession(Serializable sessionId) {
if(sessionId == null){
return null;
}
Session o = (Session)redisTemplate.opsForValue().get(SESSION_NAME+":"+sessionId);
return o;
}
解决方案:重写DefaultWebSessionManager里面的retrieveSession方法
@Bean("sessionManager")
public SessionManager sessionManager(@Qualifier("redisSessionDao")RedisSessionDao redisSessionDao) {
DefaultWebSessionManager sessionManager =new 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) {
return session;
}
}
Session session = super.retrieveSession(sessionKey);
if (request != null && sessionId != null) {
request.setAttribute(sessionId.toString(), session);
}
return session;
}
};
sessionManager.setSessionValidationSchedulerEnabled(true);
sessionManager.setSessionIdUrlRewritingEnabled(false);
sessionManager.setDeleteInvalidSessions(true);
sessionManager.setSessionIdCookie(new SimpleCookie(RedisSessionDao.SESSION_NAME));
sessionManager.setSessionDAO(redisSessionDao);
return sessionManager;
}