title: Spring-Boot @Bean producer with dynamic parameters
body: <p>I'm dealing with a set of similar Beans just differing for some properties, and what I'm trying to achieve is to have just a single method producing such a Bean but with the possibility to be "configured" or customized through some parameters, maybe with a custom @Qualifier annotation.
  Is such a thing possible?</p>
  
  <p>For example, I would like to use this @Annotation as the qualifier for autowiring the different @Beans:</p>
  
  <pre><code>import java.lang.annotation.ElementType;
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  import java.lang.annotation.Target;
  
  @Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
  @Retention(RetentionPolicy.RUNTIME)
  @Qualifier
  public @interface CustomQualifier {    
      int length();
      int height();
  }
  </code></pre>
  
  <p>Then have just a single method for producing the different @Beans, by reading the parameters of the annotation.</p>
  
  <pre><code>import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  public class DynamicReportsConfiguration {
  
      @Bean
      @CustomQualifier // Here I do not want to set the fields' value
      public MyBean produceBean() {
          // TODO Read the fields of the @CustomQualifier
          int length;
          int height;
  
          return new MyBean(length, height);
      }
  }
  </code></pre>
  
  <p>Then I just want to specify the fields on the injection point, e.g.:</p>
  
  <pre><code>@Autowired
  @CustomQualifier(length=10, height=50)
  private MyBean myBean;
  </code></pre>
  
  <p>How can I achieve such a thing, without having to create a method for each particular combination of the height and length values?</p>