Announcement Announcement Module
No announcement yet.
spring mvc request scope Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring mvc request scope

    Just a quick question the request scope visible through all user sessions or is it just applicable on an individual user session.

    example -
    I configured a SimpleFormController bean in the spring context. I have injected some properties into this bean such as a service object and a dao object. All of these dependencies are defined in the SImpleFormController in the spring-context.xml I am using ModelAndView and putting my results into it i.e. a List.

    Now since spring is defaulted to Singleton, will all users of my application see the same data since I am injecting the dependencies OR shall it be on a user session basis. No user should see another user's stuff. I login, I should only see my stuff, not the stuff from another user this clear ?

    How can I ensure this.


  • #2
    Request scope is just that, variables are in scope for a single request.

    A session is generally tied to a user, you may being confused with application scope which is visible to all .
    Last edited by travisjwarren; Jan 5th, 2009, 09:28 PM.


    • #3
      "Request scope is just that, variables are in scope for a single request.' -- Right. But since Spring handles by default all you're beans as Singletons, then in that case a variable defined within the class scope of the bean, would persist across all requests given that the singleton is alive within the spring context. Once the singleton is no longer accessible then it would be created again, This I think applies even more so to any properties that are injected into a bean, where you are using setter based injected (as is the case in my situation).

      I happen to be putting all stuff that I want to display in the view into my ModelAndView object. Then I just use the attribute property to display in jsp. Which is fine, I think lotta folks doin it that way. Here's my concern.....
      Since I am soley developing this app I am not forseeing any variables being shared across multiple sessions. What worries me is when this app gets tested, since all my stuff i wanted to show is in request scope, the users sessions could overlap in the information being displayed.

      Know what i mean...anyone...anybody....Rod...Rod Johnson you out there???


      • #4
        Don't think Rod will help you on this one except to say read the documentation and learn the MVC pattern.

        Yes the default bean scope is singleton but these beans should just populate your ModelAndView which is request scoped.