title: Spring register beans using custom annotation
body: <p>I need to register some configuration beans from another module. Here is what I have:</p>
  <pre><code>@Configuration
  public class MyConfiguration {
      @Bean
      public FirstConfig(CustomManager manager, CustomContext context) {
          return manager.get(FirstConfig.class, context);
      }
  
      @Bean
      public SecondConfig(CustomManager manager, CustomContext context) {
          return manager.get(SecondConfig.class, context);
      }
  
      @Bean
      public ThirdConfig(CustomManager manager, CustomContext context) {
          return manager.get(ThirdConfig.class, context);
      }
      // some other beans
  }
  </code></pre>
  <p>The above code works just fine, but as you can see, there are a lot of boilerplate code. So I'm thinking about creating a custom annotation to simplify this. Something like:</p>
  <pre><code>@Configuration
  @EnableConfigBeans({FirstConfig.class, SecondConfig.class, ThirdConfig.class})
  public class MyConfiguration {
      // some other beans
  }
  </code></pre>
  <p>The approach I took was to use <code>@Import</code> and implement interface <code>ImportBeanDefinitionRegistrar</code></p>
  <pre><code>public class CustomBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar
  </code></pre>
  <p>and define my annotation like this:</p>
  <pre><code>@Target({ElementType.TYPE})
  @Retention(RetentionPolicy.RUNTIME)
  @Import({CustomBeanDefinitionRegistrar.class})
  public @interface EnableConfigBeans {
      Class&lt;?&gt;[] value();
  }
  </code></pre>
  <p>However, I'm not able to autowire <code>CustomManager</code> or <code>CustomContext</code> in <code>CustomBeanDefinitionRegistrar</code> since those beans are not ready to use at that phase.</p>
  <p>Can someone please give me some suggestions on how to implement this feature? Thanks</p>