使用注释Spring的会话超时
我有基于Java的配置spring 4,我的WebAppInitializer实现了WebApplicationInitializer,我想在不使用web.xml的情况下实现会话超时我有以下类使用注释Spring的会话超时,spring,spring-mvc,session,session-timeout,Spring,Spring Mvc,Session,Session Timeout,我有基于Java的配置spring 4,我的WebAppInitializer实现了WebApplicationInitializer,我想在不使用web.xml的情况下实现会话超时我有以下类 import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; public class SessionListener implements HttpSessionListener {
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class SessionListener implements HttpSessionListener {
@Override
public void sessionCreated(HttpSessionEvent event) {
System.out.println("==== Session is created ====");
event.getSession().setMaxInactiveInterval(5*60);
}
@Override
public void sessionDestroyed(HttpSessionEvent event) {
System.out.println("==== Session is destroyed ====");
}
}
在我的WebAppInitializer上有,但是super.onStartup给了我错误,因为它不是在WebApplicationInitializer下找到的,而是AbstractAnnotationConfigDispatchers Servletilizer,我不想更改代码。是否有一个工作环境,让我可以抽出时间为自己工作
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext); // this line is giving me error
servletContext.addListener(new SessionListener());
}
救命啊 只是不要调用super.onStartup…忘记在web.xml上添加侦听器