在Spring MVC中设置会话超时 [英] setting session timeout in Spring MVC

查看:967
本文介绍了在Spring MVC中设置会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Spring中指定会话超时? 我无法在web.xml中指定。因为我在控制器中使用会话范围bean,如下所示

Is there any way of specifying session timeout in Spring? I can not specify it in web.xml. As I am using session scope bean in controller as follows

我已经通过spring xml文件配置了控制器。

I have configured controller through spring xml files.

class xyzController{

     ABCSessionScopeClass objectWhichWillBeStoredInSession;
}

我也不能使用这个

session.setMaxInactiveInterval(60*60);

还有其他办法吗?我不介意在每个会话或同时为所有会话设置超时。

Is there any other way of doing this. I don't mind setting timeout per session or for all session at the same time.

推荐答案

我无法找到任何会话通过任何Spring配置文件指定会话超时值的方法。我使用< aop:scoped-proxy> bean,这样我就不必管理会话的读/写值/对象了。现在,我也希望在不使用servlet API的情况下设置会话超时值。但看起来除了web.xml文件之外没有办法指定它。因此最终使用servlet api request.getSession()来设置超时时间。我外化时间值,以便我可以轻松地更改它而无需重新编译代码。如果有人找到更好的方法,请随时发布。如果发现更好,我可以接受这个答案。

I was not able to find any way to specify session timeout value through any Spring configuration files. I was using <aop:scoped-proxy> bean so that I don't have to manage read/write value/object to session. Now, I also want the same for setting session timeout value, without using servlets API. But looks like there is no way to specify it other than web.xml file. So ended up using servlet api request.getSession() to set timeout period. I externalized time value so that I can easily change it without recompiling the code. If anyone found better approach then please feel free to post. If found better, I can accept that as an answer.

这篇关于在Spring MVC中设置会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆