What is the default session timeout and how to configure it when using the Spring Session with Redis as the backend

The easiest way to configure session timeout when using redis repository is

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 60)

OR @EnableRedissonHttpSession(maxInactiveIntervalInSeconds = 1200) if redisson dependency is there.

The session expires when it is no longer available in the repository. Timeout can be configured with setDefaultMaxInactiveInterval(int) on both RedisOperationsSessionRepository and MapSessionRepository. Default value is 30 minutes.

If you are using spring boot, then as of version 1.3 it will automatically sync the value with the server.session.timeout property from the application configuration.

Note that one of the shortcomings when using spring session is that javax.servlet.http.HttpSessionListeners are not invoked.

If you need to react on session expiration events you can subscribe to SessionDestroyedEvent application event of your spring application.


server.session.timeout is deprecated and was replaced with server.servlet.session.timeout in Spring Boot 2.0.