title: ApplicationContext.getBean vs new keyword
body: <p><strong>I am using JSF + Spring+ Hibernate</strong> </p>
  
  <pre><code>protected @Inject ChartOfAccount chartOfAccount;
  </code></pre>
  
  <p>I basically want to populate <code>chartOfAccount</code> from the list </p>
  
  <pre><code>for (DistributionEntry de : getDistributionEntries()) {
  
       chartOfAccount.setAccount(de.getAccount());
       chartOfAccountList.add(chartOfAccount);
  }
  </code></pre>
  
  <p>for each iteration I want new object of <code>chartOfAccount</code> otherwise you know list contain same object with latest value.</p>
  
  <p><strong>Solution One: use new keyword :-p</strong> </p>
  
  <pre><code>for (DistributionEntry de : getDistributionEntries()) {
       ChartOfAccount coa= new ChartOfAccount();
       coa.setAccount(de.getAccount());
       chartOfAccountList.add(coa);
  }
  </code></pre>
  
  <p><strong>Solution Two : applicationContext.getBean</strong> </p>
  
  <pre><code>for (DistributionEntry de : getDistributionEntries()) {
       chartOfAccount= applicationContext.getBean(ChartOfAccount.class);
       chartOfAccount.setAccount(de.getAccount());
       chartOfAccountList.add(chartOfAccount);
  }
  </code></pre>
  
  <p>But I have read the certain articles that to avoid use of <code>applicationContext.getBean</code></p>
  
  <p>If I avoid to use <code>applicationContext.getBean</code> , <strong>what is the best way to handle this type of situation ?</strong> and <strong>both behavior will same? (ApplicationContext.getBean vs new keyword )</strong> </p>
  
  <blockquote>
    <p>Note: My Managed bean is @Scope("session") and Model is @Scope(BeanDefinition.SCOPE_PROTOTYPE), so as we all know that for one session it is singleton and prototype for different session.</p>
  </blockquote>