title: @Scope("prototype") bean scope not creating new bean
body: <p>I want to use a annotated prototype bean in my controller. But spring is creating a singleton bean instead. Here is the code for that:</p>
  
  <pre><code>@Component
  @Scope("prototype")
  public class LoginAction {
  
    private int counter;
  
    public LoginAction(){
      System.out.println(" counter is:" + counter);
    }
    public String getStr() {
      return " counter is:"+(++counter);
    }
  }
  </code></pre>
  
  <p>Controller code:</p>
  
  <pre><code>@Controller
  public class HomeController {
      @Autowired
      private LoginAction loginAction;
  
      @RequestMapping(value="/view", method=RequestMethod.GET)
      public ModelAndView display(HttpServletRequest req){
          ModelAndView mav = new ModelAndView("home");
          mav.addObject("loginAction", loginAction);
          return mav;
      }
  
      public void setLoginAction(LoginAction loginAction) {
          this.loginAction = loginAction;
      }
  
      public LoginAction getLoginAction() {
          return loginAction;
      }
      }
  </code></pre>
  
  <p>Velocity template:</p>
  
  <pre><code> LoginAction counter: ${loginAction.str}
  </code></pre>
  
  <p>Spring <code>config.xml</code> has component scanning enabled:</p>
  
  
  
  <pre><code>    &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.springheat" /&gt;
      &lt;mvc:annotation-driven /&gt;
  </code></pre>
  
  <p>I'm getting an incremented count each time. Can't figure out where am I going wrong! </p>
  
  <p><strong>Update</strong></p>
  
  <p>As <a href="https://stackoverflow.com/a/7621968/254477">suggested by @gkamal</a>, I made <code>HomeController</code> <code>webApplicationContext</code>-aware and it solved the problem.</p>
  
  <p>updated code:</p>
  
  <pre><code>@Controller
  public class HomeController {
  
      @Autowired
      private WebApplicationContext context;
  
      @RequestMapping(value="/view", method=RequestMethod.GET)
      public ModelAndView display(HttpServletRequest req){
          ModelAndView mav = new ModelAndView("home");
          mav.addObject("loginAction", getLoginAction());
          return mav;
      }
  
      public LoginAction getLoginAction() {
          return (LoginAction) context.getBean("loginAction");
      }
  }
  </code></pre>