springsessionspring-boottimeout

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.


Solution

  • You should be able to set the server.session.timeout in your application.properties file.

    ref: http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html

    EDIT:

    This property has changed in later versions of Spring Boot to server.servlet.session.timeout.

    ref: https://docs.spring.io/spring-boot/docs/2.4.x/reference/html/appendix-application-properties.html#server.servlet.session.timeout