Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Java Config Set Session Timeout

How can I configure my (embedded) Tomcat Session Timeout in a Spring Boot Application?

public class SessionListener implements HttpSessionListener{  @Override public void sessionCreated(HttpSessionEvent se) {     se.getSession().setMaxInactiveInterval(5*60); }  @Override public void sessionDestroyed(HttpSessionEvent se) {  }} 

I have a SessionListener but I have no idea in which class I have to add this Listener to the Context.

like image 577
Timo Ademeit Avatar asked Dec 05 '16 13:12

Timo Ademeit


People also ask

How do I set a session timeout in Spring?

Spring Security Session Timeout In the case of Tomcat we can set the session timeout by configuring the maxInactiveInterval attribute on the manager element in server. xml or using the session-timeout element in web. xml. Note that the first option will affect every app that's deployed to the Tomcat instance.

How do I set timeout in Spring boot?

@Transactional Timeouts One way we can implement a request timeout on database calls is to take advantage of Spring's @Transactional annotation. It has a timeout property that we can set. The default value for this property is -1, which is equivalent to not having any timeout at all.


1 Answers

server.session.timeout in the application.properties file is now deprecated. The correct setting is:

server.servlet.session.timeout=60s 

Also note that Tomcat will not allow you to set the timeout any less than 60 seconds. For details about that minimum setting see https://github.com/spring-projects/spring-boot/issues/7383.

like image 97
Daryl Avatar answered Oct 19 '22 19:10

Daryl