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

ε祈祈猫儿з 提交于 2019-11-30 10:48:47

问题


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?


回答1:


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

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 60)

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.




回答2:


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



来源:https://stackoverflow.com/questions/32501541/what-is-the-default-session-timeout-and-how-to-configure-it-when-using-the-sprin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!