title: Spring Boot Factory Bean Creation Order
body: <p>I am trying to dynamically register Beans in Spring Boot, however the order of how the beans are created always result in a <code>NoSuchBeanDefinitionException</code> if it try to autowire one of the dynamic beans.</p>
  <p>My setup consists of two projects, one spring-boot-starter project and the actual spring-boot application.</p>
  <p>The actual application registers a <code>BeanDefinitionRegistryPostProcessor</code> that adds the bean definitions. The instances itself are constructed via another bean defined in the starter project that itself takes another bean as dependency.</p>
  <p>In order to consume the dynamically registered bean, I created a class annotated with <code>@Component</code> and defined a constructor expecting said bean as parameter.
  When I debug the application by setting <code>@Autowired(required=false)</code>, I can see that the constructor of my component is called before the dynamic bean has been created. Moreover, not even the factory bean has been created at that time.</p>
  <p>Added <code>@DependsOn</code> with the factory bean's name to component resulted the factory being created first, but not the dynamic beans.</p>
  <p>Setting <code>@DependsOn</code> with the dynamic bean's name works, but that doesn't seem to be the correct way to solve this issue.</p>
  <p>Why is Spring creating my beans in the wrong order and what can I do solve this?</p>
  <p><strong>EDIT:</strong></p>
  <p>I was able to reproduce the issue in a sample repository:<br />
  <a href="https://github.com/maveeee/spring-dynamic-bean-demo/" rel="nofollow noreferrer">https://github.com/maveeee/spring-dynamic-bean-demo/</a></p>