title: How to get beans created by FactoryBean spring managed?
body: <p>The <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-extension-factorybean" rel="noreferrer">FactoryBean</a> can be used to programmatically create objects which might require complex instantiation logic. </p>
  
  <p>However, it seems that the beans <em>created</em> by the <code>FactoryBean</code> doesn't become spring managed.  Is this interpretation correct? If so, are there any nice workarounds? A short code sample is included to illustrate my problem. </p>
  
  <p>ApplicationContext:</p>
  
  <pre><code>&lt;bean id="searcher" class="some.package.SearcherFactory" /&gt; 
  &lt;bean id="service" class="some.package.Service" /&gt; 
  </code></pre>
  
  <p>Factory implementation:</p>
  
  <pre><code>public class SearcherFactory implements FactoryBean&lt;Searcher&gt; {
  
      @Override
      public Searcher getObject() throws Exception {
          return new Searcher(); // not so complex after all ;)
      }
  
      @Override
      public Class&lt;Searcher&gt; getObjectType() {
          return Searcher.class;
      }
      .... 
  }
  </code></pre>
  
  <p>Class created by the factory: </p>
  
  <pre><code>public class Searcher() {
        private Service service;
  
        @Autowired
        public void setService(Service service) {
             // never invoked
             this.service=service;
        } 
  }
  </code></pre>