Controlling JDBCSession Timeout

Published by Bilal Kaun on

You might have noticed that Spring Boot’s server.session.timeout does not apply if JDBCSession library is autoconfigured. Which means, the standard way to set default session timeout no longer applies.

The appropriate way to set the timeout in this case is through the @EnableJdbcHttpSession annotation’s maxInactiveIntervalInSeconds like so.

// Set the default session timeout from 1800 (the library's default) to 5 minutes (as an example)
@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = 300)

This is fine if you don’t mind moving the config magic values into the code, however all our properties are injected through a secrets and property management solution, including the server.session.timeout property. Thankfully the underlying JdbcOperationsSessionRepository class allows setting the default the maxInactiveIntervalInSeconds. So the solution is to bind to the ApplicationReady event and set variable.

private Integer serverTimeout


Github Hosted Example

If the embedded gist is not displaying, visit here:


Leave a Reply

Your email address will not be published. Required fields are marked *