我已经实现了 HttpSessionListiner 但它不起作用。
用调试器检查 - 输入 servlet 后创建新会话,登录后 JSESSION_ID 发生变化,但 session.getCreateTime() 保持不变(会话保持不变?)。
使用注释,Spring Security。也许我错过了 Spring Security 中的一些配置?
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.log4j.Logger;
@WebListener
public class SessionListener implements HttpSessionListener {
private static int totalActiveSessions;
private static final Logger log = Logger.getLogger(SessionListener.class);
@Override
public void sessionCreated(HttpSessionEvent se) {
totalActiveSessions++;
log.warn("sessionCreated - add one session into counter");
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
totalActiveSessions--;
log.debug("sessionDestroyed - deleted one session from counter");
}
}
@Bean
public ServletListenerRegistrationBean<HttpSessionListener> sessionListener() {
return new ServletListenerRegistrationBean<HttpSessionListener>(new sessionListener());
}
这个 bean 注册了我的监听器。我还没有找到其他解决方案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)