title: How to conditionally create a bean using Spring?
body: <p>I have this pattern:</p>
  
  <pre><code>public class Factory {
      public GenericBean get(ContextEnum context, OneTypeArgs args) {
          switch (context) {
          case OneContext:
              Action a = new OneAction(args);
              return new GenericBean(a);
          case TwoContext:
              Action b = new SecondAction();
              return new GenericBean(b);
          default:
              throw new IllegalArgumentException();
          }
      }
  }
  </code></pre>
  
  <p>How can I avoid the switch statement and configure Spring to be able to construct itself this kind of objects grape ?</p>
  
  <p>I have two problems and I don't know how to handle them:</p>
  
  <ol>
  <li>Action construction depends on a context to be able to find correct implementation.</li>
  <li>Constructor arguments are dynamic.</li>
  </ol>