我有一个场景,在一段时间不活动之后会话将过期,但是我需要保持Spring 4 MVC永远保持会话存活。下面是我的Spring Initializer类,
'''公共类SpringWebAppInitializer实现WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.register(ApplicationContextConfig.class);
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
"SpringDispatcher", new DispatcherServlet(appContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}'''
在标记中使用-1,因为-1用于会话永不过期。
Web.xml:
<session-config>
<session-timeout>-1</session-timeout>
</session-config>