How to store session in Spring MVC

2019-03-08 03:51发布

What's the best way of storing session related data of a user (like, for example a log of recent actions a user has done) in a Spring MVC (2.5) web application ?

Using the classic javax.servlet.http.HttpSession or by specifying scope="session" in controller beans, and storing the data in a session object ?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-08 04:05

Session-scoped beans (using scope="session") is the cleanest approach. This removes the need to interact with the session yourself.

If you want to autowire a session-scoped bean in to the controller, you either need to make the controller session-scoped itself, or use a scoped-proxy to wire it into a singleton controller, as described here. Either approach is valid.

查看更多
登录 后发表回答