title: Spring 3 Autowired BeanInitializationException
body: <p>I have a big problem with @Autowired that always return with exception</p>
  
  <blockquote>
    <p>Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'serviceFactory' is required for bean 'A'</p>
  </blockquote>
  
  <p>Here are the brief of everything (I am using Spring 3.2 and I have put all the jar in the right place WEB-INF/lib).</p>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:p="http://www.springframework.org/schema/p" 
          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.2.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.2.xsd"&gt;
  
  &lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.sc" /&gt;
  
  &lt;!-- Comment out - we are going to use @Component @Autowired - 2014-01-07
  &lt;bean id="A" class="com.sc.A"&gt;
    &lt;property name="serviceFactory" ref="serviceFactoryBean" /&gt;
  &lt;/bean&gt; 
  --&gt;
  
  &lt;bean id="serviceFactoryBean" class="com.sc.ServiceFactory" autowire="byName" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Content of Class com.sc.A</p>
  
  <pre><code>@Component
  public class A
  {
  
  private Logger logger = Logger.getLogger(A.class);
  
  // @Autowired -- 2014-01-07 comment out as not need it since annotation in setter below
  // @Qualifier("serviceFactoryBean")
  private ServiceFactory serviceFactory;
  
  public A()
  { }
  
  @Autowired // add 2014-01-07
  @Required
  public void setServiceFactory(ServiceFactory serviceFactory)
  {
    this.serviceFactory = serviceFactory;
  }
  
  public boolean checkSomething() 
  {
    if(this.serviceFactory == null)
     logger.error("serviceFactory is null. Autowired failed");
  
   // do something
  }
  
  
  } // end of class A
  </code></pre>
  
  <p>Content of class com.sc.ServiceFactory</p>
  
  <pre><code>// @Component -- comment out 2014-01-07
  public class ServiceFactory
  {
    // do whatever
  }
  </code></pre>
  
  <p>then I compiled the classes and ran it in jetty and when jetty went up, It always throw up long exception of </p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'A' defined in URL ... Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'serviceFactory' is required for bean 'A'</p>
  </blockquote>
  
  <p>I have try many combination with and without annotation to no avail. It is very frustrating to face this error.</p>
  
  <p>Please help</p>