title: Choose which implementation to inject at runtime spring
body: <p>I have the following classes:</p>
  
  <pre><code>public interface MyInterface{}
  
  public class MyImpl1 implements MyInterface{}
  
  public class MyImpl2 implements MyInterface{}
  
  public class Runner {
          @Autowired private MyInterface myInterface;
  }
  </code></pre>
  
  <p>What I want to do is decide, whilst the app is already running (i.e. <strong>not</strong> at startup) which Implementation should be injected into <code>Runner</code>.</p>
  
  <p>So ideally something like this:</p>
  
  <pre><code>ApplicationContext appContext = ...
  Integer request = ...
  
  Runner runner = null;
  if (request == 1) {
          //here the property 'myInterface' of 'Runner' would be injected with MyImpl1
          runner = appContext.getBean(Runner.class) 
  }
  else if (request == 2) {
          //here the property 'myInterface' of 'Runner' would be injected with MyImpl2
          runner = appContext.getBean(Runner.class)
  }
  runner.start();
  </code></pre>
  
  <p>What is the best way to accomplish this?</p>