title: Can we have a factory class as spring bean and have a factory method returning multiple spring beans based on the condition?
body: <p>I want to return multiple spring beans based on the condition in the factory class.</p>
  
  <p>Is this a good practice?</p>
  
  <p>Any better ways to write the following piece of code?.
  Any other design patterns suitable here?</p>
  
  <p>Below is the code snippet:</p>
  
  <pre><code>package com.test;
  
  import org.springframework.stereotype.Component;
  import javax.annotation.Resource;
  
  
  @Component
  public class InstanceFactory {
  
      @Resource(name = "instance1")
      private Instance instance1;
  
      @Resource(name = "instance2")
      private Instance instance2;
  
      public Instance getService(Condition condition) {
          if (condition.one() &amp;&amp; condition.two()) {
              return instance2;
          } else {
              return instance1;
          }
      }
  }
  </code></pre>