title: Spring - getting bean at runtime with custom qualifier
body: <p>I created a custom Spring <code>@Qualifier</code> annotation:</p>
  
  <pre><code>@Target({
          ElementType.FIELD,
          ElementType.METHOD,
          ElementType.PARAMETER, 
          ElementType.TYPE,
          ElementType.ANNOTATION_TYPE
  })
  @Retention(RetentionPolicy.RUNTIME)
  @Qualifier
  public @interface Database {
      String value() default "";
  }
  </code></pre>
  
  <p>I then applyed this annotation to the various implementing Beans:</p>
  
  <pre><code>@Repository
  @Database("mysql")
  class MySqlActionRepository implements ActionRepository {}
  
  @Repository
  @Database("oracle")
  class OracleActionRepository implements ActionRepository {}
  
  @Repository
  @Database("sqlserver")
  class SqlServerActionRepository implements ActionRepository {}
  </code></pre>
  
  <p>Now, being that at runtime, only one of these Beans has to be available for injection, I created a <code>@Primary</code> Bean method.</p>
  
  <pre><code>@Bean
  @Primary
  ActionRepository actionRepository(
          final ApplicationContext applicationContext,
          final Configuration configuration) {
      final var database = configuration.getString("...");
      return BeanFactoryAnnotationUtils.qualifiedBeanOfType(
              applicationContext,
              ActionRepository.class,
              database
      );
  }
  </code></pre>
  
  <p>However this solution <strong>does not</strong> work with my custom annotation. It works only when using the standard <code>@Qualifier</code> one.</p>
  
  <p>Any idea how I could solve this issue?</p>