Reputation: 629
I am using Spring Sessions with Postgres. The sessions are persisted into my Postgres database using the JdbcOperationsSessionRepository
.
The default inactive time that I am using for my sessions is 30 days. Once a user logs in, I do request.getSession().setMaxInactiveInterval()
and change it to 180 days.
However for some reason the 180 days is not being respected and sessions keep getting deleted every hour. For example:
This session should have lasted 180 days but it got deleted as soon as the next hour started.
Does anyone know how I can stop these sessions from getting deleted and have them stick around for 180 days?
I am guessing this function has something to do with this.
Here's the part of my application that extends the user's max inactive interval:
private void setupSession(HttpServletRequest request, User user) {
HttpSession session = request.getSession();
session.setMaxInactiveInterval(15552000);
session.setAttribute("user-id", user.id);
}
Upvotes: 2
Views: 2464
Reputation: 2389
As indicated in the comments, this is a problem with Spring Session JDBC integration which has been reported in gh-580.
To work around this until the solution is delivered, you can extend the JdbcOperationsSessionRepository
and override cleanUpExpiredSessions
method. After that you just need to override the default JDBC session repository bean by providing your bean that extends JdbcOperationsSessionRepository
and is named sessionRepository
(bean name is important since it has to match the one in JdbcHttpSessionConfiguration
in order to override it).
For example:
@EnableJdbcHttpSession
class SessionConfig {
// omitted data source & tx manager config
@Bean
MyJdbcOperationsSessionRepository sessionRepository(...) {
return new ...
}
}
You can find the solution for cleanUpExpiredSessions
outlined in comments on gh-580.
Upvotes: 1