title: @SessionAttributes and @ResponseBody do not work together
body: <p>I have created a very simple "test" controller that keeps a counter in session to print how many times a request handler is called. </p>
  
  <pre><code>@Controller
  @SessionAttributes("counter")
  public class MyController {
  
      @ModelAttribute("counter")
      public Counter addCounter(){
          System.out.println("Counter added to model");
          return new Counter();
      }
  
  
      @RequestMapping("printCounter")
      @ResponseBody
      public String printCounter(Model model){
  
          Counter counter = (Counter)model.asMap().get("counter");
          int currVal = counter.getValue();
          System.out.println("Current value: " + currVal);
  
          counter.increment();
  
  
          return "hello-view";
      }
  
  }
  </code></pre>
  
  <p>Every thing works fine, but when I try to use   @ResponseBody on the response  it fails with the following error:</p>
  
  <pre><code>java.lang.IllegalStateException: Cannot create a session after the response has been   committed
  </code></pre>
  
  <p>I have found several work around. I know the error happens  because spring has already flushed the response when trying to add the counter to the session. What I do not know is why spring is doing so. </p>
  
  <p>Since the issue has been there for so long I imagine it is done on propose.</p>
  
  <p>Does any body know what is the motivation for implementing it this way?</p>
  
  <p>Why can we store data in the session if the method  is returning body content but we can if it  returns a view name?</p>
  
  <p>Thanks in advance.</p>