Issue
I have a scenario where session is getting expired after some time of inactivity, But i need to keep Spring 4 MVC keep session alive forever. Below is my Spring Initializer class,
'''public class SpringWebAppInitializer implements 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("/");
}
}'''
Solution
Use -1 in tag because -1 is for session never expires.
Web.xml:
<session-config>
<session-timeout>-1</session-timeout>
</session-config>
Answered By - danieltc07