简体   繁体   English

Spring MVC,@ SessionAttribute和可伸缩性

[英]Spring MVC, @SessionAttribute and scalability

We are building a Spring-MVC web application for 80 000 users. 我们正在为8万用户构建Spring-MVC Web应用程序。

I see a lot of controllers in the petclinic example using : @SessionAttribute annotation and SessionStatus status ... status.setComplete() to store and remove the beans from the HTTP Session. 我在petclinic示例中看到很多控制器使用: @SessionAttribute注释和SessionStatus status ... status.setComplete()来存储和删除HTTP会话中的bean。 Very useful indeed. 非常有用。

Is it the best way to go if you plan to build an application for 80 000 users ? 如果您计划为8万用户构建应用程序,这是最好的方法吗? Could you still use session load balancing and session failover if you plan to store all your form data like this ? 如果您打算存储所有这样的表单数据,您仍然可以使用会话负载平衡和会话故障转移吗?

It will probably not meet your needs, no. 它可能无法满足您的需求,不。 There are two principle problems with the built in implementation: 内置实现有两个主要问题:

  1. It doesn't really support tabbed browsing. 它并不真正支持选项卡式浏览。 If a user loads the same screen in multiple browser tabs, the two tabs accessing one controller are going to clobber each other's session attribute data. 如果用户在多个浏览器选项卡中加载相同的屏幕,则访问一个控制器的两个选项卡将会破坏彼此的会话属性数据。

  2. If users don't follow your "planned" navigation path that setComplete() call will get missed and the object hang around indefinitely until the session expires and is cleaned up. 如果用户不遵循您的“计划”导航路径,则会错过setComplete()调用,并且对象会无限期地挂起,直到会话到期并被清除。

Number 1 may or may not be a concern depending on how your app is designed and what it does. 1号可能是也可能不是问题,具体取决于您的应用程序的设计方式和作用。 (some things, eg, Banks, deliberately thwart mult-tabbed usage anyway) But most users I think would expect to be able to edit User A's profile in one tab and User B's profile in another tab and not have submitting one form break the other screen. (有些事情,例如,银行,无论如何故意阻止多标签的使用)但我认为大多数用户希望能够在一个标签中编辑用户A的个人资料,而在另一个标签中编辑用户B的个人资料而没有提交一个表格打破另一个屏幕。

Number 2 you could work around by always submitting a screen into its own controller then redirecting after cleanup, but that's a lot of work if you aren't already building that way. 您可以通过将屏幕提交到自己的控制器然后在清理后重定向来解决问题,但如果您尚未构建这种方式,则需要进行大量工作。

The good news is org.springframework.web.bind.support.SessionAttributeStore is a recognized extension point! 好消息是org.springframework.web.bind.support.SessionAttributeStore是一个公认的扩展点! You can provide any implementation of that you like and inject it in your dispatcher servlet. 您可以提供您喜欢的任何实现,并将其注入您的调度程序servlet。 You don't even need to use the Web Session to store information if you want to avoid bloating it up with business objects. 如果要避免使用业务对象使其膨胀,则甚至不需要使用Web会话来存储信息。 You could put that actual storage in a backend terracotta cluster for example, and not worry about it being compatible with your clustering strategy. 例如,您可以将实际存储放在后端兵马俑集群中,而不用担心它与您的集群策略兼容。

-- -

And then there's always option Gamma if you really need true scalability: rework it into a RESTful strategy that doesn't rely serverside state in the first place :) 如果你真的需要真正的可扩展性,那么总有选项Gamma:将它重新编写成一个RESTful策略,它不依赖于服务器端状态:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring MVC @RequestParam和@SessionAttribute - Spring MVC @RequestParam and @SessionAttribute Spring MVC - 页面之间的变量,以及取消设置 SessionAttribute - Spring MVC - Variables between pages, and Unsetting a SessionAttribute 在带注释的控制器spring MVC中使用sessionAttribute - using sessionAttribute in annotated controller spring MVC 如何在Spring MVC中使用@ModelAttributes和@SessionAttribute - How to use @ModelAttributes and @SessionAttribute in spring MVC Spring MVC @SessionAttribute Missing session 类型 String[] 属性错误 - Spring MVC @SessionAttribute Missing session attribute of type String[] error Spring - SessionAttribute问题 - Spring - SessionAttribute problem 我尝试使用@SessionAttribute Spring MVC注释将数据存储到会话中时遇到错误 - I got Error While i am trying to store data into session using @SessionAttribute Spring MVC anotation Spring将自动连线的SessionAttribute注入服务层 - Spring Inject Autowired SessionAttribute into Service Layer Spring 3 AJAX POST请求与@RequestBody以及@ModelAttribute和@SessionAttribute一起使用? - Spring 3 AJAX POST request with @RequestBody and @ModelAttribute and @SessionAttribute used together? 是否要使用Spring SessionAttribute计算系统中的登录成员数? - Want to calculate number of login members in System using Spring SessionAttribute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM