title: Spring prototype beans in combination with singleton beans and dependency injection. Is there an approach that is configuration only?
body: <p>I have a singleton bean which needs for each call of a function to return a reference to a different (new) prototype bean. The only way that I can think of doing this is to programmatically retrieve a new prototype bean instance from the BeanFactory/ApplicatioContext by invoking its getBean() method. Code sample will follow...</p>
  
  <p>Is there a better way to do this? Only via configuration, hopefully? (Personally, I doubt there is...)  </p>
  
  <pre><code>&lt;bean id="protoBean" scope="prototype"
          class="com.blahblah.ProtoBean" /&gt;
  
  &lt;bean id="singletonBean"
          class="com.blahblah.SingletonBean" /&gt;
  
  public class ProtoBean {
  
      ....
  }
  
  public class SingletonBean {
  
      private BeanFactory factory;
  
      public ProtoBean dispense() {
          return (ProtoBean) factory.getBean("protoBean");
      }
  
      ....
  }
  </code></pre>