title: spring - ApplicationContext registerBean autowiring fails but getBean works in Spring 5
body: <p>I'm using a configuration class that uses dynamic bean registration:</p>
  
  <pre><code>@Configuration
  public class ConfigClass {
  
      @Autowired
      private GenericApplicationContext applicationContext;
  
      @PostConstruct
      private void init() {
          System.out.println("init");
          applicationContext.registerBean("exService", ExecutorService.class, () -&gt; Executors.newFixedThreadPool(10), bd -&gt; bd.setAutowireCandidate(true));
          System.out.println("init done");
      }
  }
  </code></pre>
  
  <p>If I try to autowire the bean, application startup fails with error <code>Field exService in com.example.DemoApplication required a bean of type 'java.util.concurrent.ExecutorService' that could not be found.</code></p>
  
  <p>From the logs I can see that the init method on config class wasn't called before the error as the two system out statements were not printed out.</p>
  
  <p>However, when I use <code>applicationContext.getBean(ExecutorService.class)</code> it does work without any issues.</p>
  
  <p>Anyway I can get the bean to Autowire?</p>
  
  <p>I'm deliberately not using the <code>@Bean</code> annotation because I need to register the beans dynamically based on certain conditions.</p>