title: Spring autowire object using factory method
body: <p>I'm trying to figure out how to change this java code into spring</p>
  
  <pre><code>private MyObject myObject = MyObjectFactory.getService();
  </code></pre>
  
  <p>In my Foo.java class I have</p>
  
  <pre><code>@Autowired
  private MyObject myObject;
  </code></pre>
  
  <p>In the spring xml, I have:</p>
  
  <pre><code>&lt;bean id="MyObject" class="path.to.MyObjectFactory" factory-method="getService"&gt;&lt;/bean&gt;
  
  &lt;bean id="Foo" class="path.to.Foo"&gt;
      &lt;property name="myObject" ref="MyObject"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The error is </p>
  
  <pre><code>No matching bean of type [path.to.MyObject] found for dependency: 
  expected at least 1 bean which qualifies as autowire candidate for this dependency.
  </code></pre>