title: Spring - Programmatically generate a set of beans
body: <p>I have a Dropwizard application that needs to generate a dozen or so beans for each of the configs in a configuration list. Things like health checks, quartz schedulers, etc.</p>
  
  <p>Something like this:</p>
  
  <pre><code>@Component
  class MyModule {
      @Inject
      private MyConfiguration configuration;
  
      @Bean
      @Lazy
      public QuartzModule quartzModule() {
          return new QuartzModule(quartzConfiguration());
      }
  
  
      @Bean
      @Lazy
      public QuartzConfiguration quartzConfiguration() {
          return this.configuration.getQuartzConfiguration();
      }
  
      @Bean
      @Lazy
      public HealthCheck healthCheck() throws SchedulerException {
          return this.quartzModule().quartzHealthCheck();
      }
  }
  </code></pre>
  
  <p>I have multiple instances of MyConfiguration that all need beans like this. 
  Right now I have to copy and paste these definitions and rename them for each new configuration.</p>
  
  <p>Can I somehow iterate over my configuration classes and generate a set of bean definitions for each one?</p>
  
  <p>I would be fine with a subclassing solution or anything that is type safe without making me copy and paste the same code and rename the methods ever time I have to add a new service.</p>
  
  <p>EDIT: I should add that I have other components that depend on these beans (they inject <code>Collection&lt;HealthCheck&gt;</code> for example.)</p>