title: When do @SessionAttributes in SpringMVC get removed? (With code sample)
body: <p>Under what exact circumstances do @SessionAttributes get cleared? I've discovered some confusing behaviour when trying to use two models in a page. </p>
  
  <p>When I do a GET followed by a POST using this controller...</p>
  
  <pre><code>@Controller
  @RequestMapping("/myPage*")
  @SessionAttributes(value = {"object1", "object2"})
  public class MyController {
  
    @RequestMapping(method = RequestMethod.GET)
    public String get(Model model) {
        model.addAttribute("object1", new Object1());
        model.addAttribute("object2", new Object2());
        return "myPage";
    }
  
    @RequestMapping(method = RequestMethod.POST)
    public String post(@ModelAttribute(value = "object1") Object1 object1) {
        //do something with object1
        return "myPage";
    }
  }
  </code></pre>
  
  <p>...object2 gets cleared from the Model. It no longer exists as a @SessionAttribute and cannot be accessed on my view page.</p>
  
  <p>However if the signature of the second method is modified to this...</p>
  
  <pre><code>public String post(@ModelAttribute(value = "object1") Object1 object1,
                     @ModelAttribute(value = "object2") Object2 object2) {
  </code></pre>
  
  <p>...then object2 does not get cleared from the model and is available on my view page.</p>
  
  <p>The javadoc for @SessionAttributes says:</p>
  
  <blockquote>
    <p>... attributes will be removed once
    the handler indicates completion of
    its conversational session.</p>
  </blockquote>
  
  <p>But I don't see how I have indicated completion of the conversational session in the first example but not in the second example.</p>
  
  <p>Can anyone explain this behaviour or is it a bug?</p>