title: Programmatic Bean registration
body: <p>i would like to understand what is the programmatic equivalent of a @Bean annotated bean registration</p>
  
  <p>Lets say i have a class like this:</p>
  
  <pre><code>@Configuration
  public class SimpleConfiguration {
      @Bean
      public BigDecimal aDecimal( String example ) {
          return new BigDecimal( example );
      }
  }
  </code></pre>
  
  <p>here is what i think happens here:</p>
  
  <ol>
  <li>somehow spring register this method as a factory for a bean named
  "aDecimal" of type BigDecimal, with a dependency on a bean of type
  String</li>
  <li>at some point this method will be called with the right bean as
  parameter and the result will be the instance associated to the
  "aDecimal" bean.</li>
  </ol>
  
  <p>If i wanted to do the same with something like this:</p>
  
  <pre><code>@Configuration
  public class DynamicConfiguration {
  
      public void registerDefinition() {
          /* i know it can't be like this but i hope it's clear what i mean */
          register( "aDecimal", (example) -&gt; aDecimal( example ) );
      }
  
      public BigDecimal aDecimal( String example ) {
          /* this could be any kind of complex bean creation method */
          return new BigDecimal( example );
      }
  }
  </code></pre>
  
  <p>what would be the right way to achieve this result?</p>
  
  <p>i already researched a bit about this, and i found for example</p>
  
  <p><a href="https://stackoverflow.com/questions/25160221/how-do-i-create-beans-programmatically-in-spring-boot">How do I create beans programmatically in Spring Boot?</a></p>
  
  <p>but this kind of registration doesn't seem as powerful as the annotation, and let's spring instatiate the bean, i want the bean to be instatied by a provided method</p>
  
  <p><a href="https://stackoverflow.com/questions/3370161/how-to-programmatically-create-bean-definition-with-injected-properties">How to programmatically create bean definition with injected properties?</a></p>
  
  <p>and this is missing the ability to call a method with injected bean parameters.</p>
  
  <p>the reason i want to do this, is that i have some configuration classes that hold a lot of the same kind of beans with different qualifiers, based  on a configuration file.
  now every time the configuration file expands, i need to add new beans and configurations ( many of these are spring SessionFactories and SpringIntegration flows so i need these things to be spring beans )</p>