title: How to get a bean dynamically using Custom Qualifier Annotation
body: <p>We're using Custom Qualifier Annotations to create and inject beans. How can we select a bean dynamically at runtime by just specifying the Custom Qualifiers. </p>
  
  <p>Custom Qualifier : </p>
  
  <pre><code>@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE,
          ElementType.PARAMETER })
  @Retention(RetentionPolicy.RUNTIME)
  @Qualifier
  public @interface PlatformQualifiers {
  
      public static enum OperatingSystems {
          IOS, ANDROID
      }
  
      OperatingSystems operatingSystem() default OperatingSystems.IOS;
  
      public enum DeviceTypes {
          Mobile, Tablet, ANY, Other
      }
  
      DeviceTypes[] deviceType() default { DeviceTypes.ANY };
  }
  </code></pre>
  
  <p>Bean Interface : </p>
  
  <pre><code>@FunctionalInterface
  public interface Platform {
  
      String getDeviceDetails();
  }
  </code></pre>
  
  <p>Bean Configs : </p>
  
  <pre><code>@Configuration
  public class PlatformConfig {
  
      @Bean
      @PlatformQualifiers(operatingSystem = OperatingSystems.IOS, deviceType = DeviceTypes.Mobile)
      public Platform getIphone6() {
          return () -&gt; "iphone6";
      }
  
      @Bean
      @PlatformQualifiers(operatingSystem = OperatingSystems.IOS, deviceType = DeviceTypes.Tablet)
      public Platform getIpad() {
          return () -&gt; "ipad3";
  
      }
  
      @Bean
      @PlatformQualifiers(operatingSystem = OperatingSystems.ANDROID, deviceType = DeviceTypes.Mobile)
      public Platform getAndroidPhone() {
          return () -&gt; "AndroidPhoneSamsung";
      }
  
  }
  </code></pre>
  
  <p>Current Application Code : </p>
  
  <pre><code>@Configuration
  @ComponentScan
  public class MainApplication {
  
      @Autowired
      @PlatformQualifiers(operatingSystem = OperatingSystems.IOS, deviceType = DeviceTypes.Mobile)
      Platform iphone;
  
  
      @Autowired
      @PlatformQualifiers(operatingSystem = OperatingSystems.ANDROID, deviceType = DeviceTypes.Mobile)
      Platform androidPhone;
  
      public  void getDevice(String osType, String deviceType ) {
          if(osType == "ios" &amp;&amp; deviceType == "mobile") {
              System.out.println(iphone.getDeviceDetails());
          }
  
          if(osType == "android" &amp;&amp; deviceType == "mobile") {
              System.out.println(androidPhone.getDeviceDetails());
          }
  
      }
  
      public static void main(String[] args) {
          ApplicationContext context = new AnnotationConfigApplicationContext(MainApplication.class);
          MainApplication mainApplication = context.getBean(MainApplication.class);
          mainApplication.getDevice("ios" ,"mobile");
          mainApplication.getDevice("android" , "mobile");
  
  
      }
  
  }
  </code></pre>
  
  <p>I am looking for a solution like where on runtime I can access bean using the qualifiers, something like this : </p>
  
  <pre><code>@Configuration
  @ComponentScan
  public class MainApplication2 {
      @Autowired
      ApplicationContext context;
  
      public  void getDevice(DeviceTypes deviceType, OperatingSystems osType ) {
             &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Looking of something of type following : 
              Platform p =    context.getBean(some input consisting to identify bean by  deviceType and osType)
  
  
              System.out.println(p.getDeviceDetails());
          }
  
      public static void main(String[] args) {
          ApplicationContext context = new AnnotationConfigApplicationContext(MainApplication2.class);
          MainApplication2 application = context.getBean(MainApplication2.class);
          application.getDevice(DeviceTypes.Mobile, OperatingSystems.ANDROID);
      }
  }
  </code></pre>
  
  <p>In this case, How can I get a bean from applicationContext on runtime based on the DeviceTypes and OperatingSystems ? </p>