title: Is it possible to inject a bean defined with @Component as an argument to a BeanFactoryPostProcessor?
body: <p>And if so which configuration is needed? Is this not recommended?</p>
  
  <p>The annotated class:</p>
  
  <pre><code>package com.springbug.beanfactorydependencyissue;
  
  import javax.annotation.Resource;
  import org.springframework.stereotype.Component;
  
  @Component
  public class DependantBean {
  
      @Resource
      DependencyBean dependencyBean; // Isn't initialized correctly
  
      public DependencyBean getDependencyBean() {
          return dependencyBean;
      }
  }
  </code></pre>
  
  <p>The dependency bean that fails:</p>
  
  <pre><code>package com.springbug.beanfactorydependencyissue;
  
  import org.springframework.stereotype.Component;
  
  @Component
  public class DependencyBean {
  
  }
  </code></pre>
  
  <p>Testcase:</p>
  
  <pre><code>package com.springbug.beanfactorydependencyissue;
  
  import static org.fest.assertions.Assertions.assertThat;
  
  import javax.annotation.Resource;
  
  import org.springframework.test.context.ContextConfiguration;
  import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
  import org.testng.annotations.Test;
  
  import com.springbug.beanfactorydependencyissue.DependantBean;
  
  @ContextConfiguration(locations = "/applicationContext.xml")
  public class AppTest extends AbstractTestNGSpringContextTests {
  
      @Resource
      private DependantBean annotatedBean;
  
      @Test
      public void testThatDependencyIsInjected() {
          // Fails as dependency injection of annotatedBean.dependencyBean does not work
          assertThat(annotatedBean.getDependencyBean()).isNotNull();
      }
  }
  </code></pre>
  
  <p>A custom BeanFactoryPostProcessor with the "faulty" dependency:</p>
  
  <pre><code>package com.springbug.beanfactorydependencyissue;
  
  import org.springframework.beans.BeansException;
  import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
  import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  public class BeanFactoryPostProcessorConfiguration {
  
      /**
       * The {@link DependantBean} here causes the bug, can
       * {@link BeanFactoryPostProcessor} have regular beans as dependencies?
       */
      @Bean
      public static BeanFactoryPostProcessor beanFactoryPostProcessor(
              DependantBean dependantBean) {
          return new BeanFactoryPostProcessor() {
  
              public void postProcessBeanFactory(
                      ConfigurableListableBeanFactory beanFactory)
                      throws BeansException {
  
              }
          };
      }
  }
  </code></pre>
  
  <p>applicationContext.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="com.springbug.beanfactorydependencyissue" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Why can't <code>BeanFactoryPostProcessorConfiguration</code> reference <code>DependantBean</code>?</p>
  
  <p>The resulting <code>DependantBean</code> instance in <code>AppTest</code> is not null, i.e it's created by spring, but its dependencies (<code>DependencyBean</code>) are null. The fact that Spring doesn't complain at all leads me to believe that this is a bug within spring. Should this use-case be supported or not?</p>
  
  <p>Btw, I'm using spring-*-3.1.1.RELEASE.jar
  Btw 2: the code to reproduce the bug can also be found <a href="https://github.com/jontejj/spring-inject-test" rel="noreferrer">here</a>.</p>