title: In SpringMVC Controller layer, @Scope("prototype") vs @Scope("singleton")
body: <p>I have the following Controller code using SpringMVC:</p>
  
  <pre><code>@Controller
  @Scope("prototype")
  @RequestMapping("/messages")
  public class MessageController {
      @RequestMapping(value="/index", method=RequestMethod.GET)
      @ResponseStatus(HttpStatus.OK)
      @ResponseBody
      public String displayAllMessages(ModelMap model) {
          System.out.println(this.hashCode());
          // processing
          return "messages";
      }
  }
  </code></pre>
  
  <p>When use <code>@Scope("prototype")</code>, each request comes, the output of <code>this.hashCode()</code> are different, meaning that when each request comes, a new <code>MessageController</code> instance will be created.</p>
  
  <p>If not use <code>@Scope("prototype")</code>, default will be <code>@Scope("singleton")</code>, each request comes, the output of <code>this.hashCode()</code> are same, meaning only one <code>MessageController</code> instance is created.</p>
  
  <p>I'm not sure when should use <code>@Scope("prototype")</code>, when not?</p>