22

My application currently use Spring Session together with Redis as the backend.

I searched into the official documentation for Spring Session but was not able to find what the default session timeout is when using that module. Also I am not sure how to change that default timeout if necessary.

Can someone please advise?

informatik01
  • 16,038
  • 10
  • 74
  • 104
balteo
  • 23,602
  • 63
  • 219
  • 412

2 Answers2

41

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.

Kusum
  • 241
  • 5
  • 20
tsachev
  • 1,111
  • 10
  • 14
8

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

Fedor
  • 559
  • 1
  • 7
  • 19
  • How about WebFlux, the option didn't work with webflux – bzhu Jun 03 '20 at 06:52
  • What is the difference between the properties `spring.session.timeout`and `server.servlet.session.timeout` ? I want to control `@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = ...)` by an external property. – Alexander R. Dec 29 '21 at 08:55