title: Support for autowiring in a class not instantiated by spring (3)
body: <p>I realize this should be really basic but I haven't found a second step example after Helloworld</p>
  
  <p>So what I have is:</p>
  
  <p>spring config xml called spring-beans.xml:</p>
  
  <pre><code>&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-2.5.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="org" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>A spring context initialized class:</p>
  
  <pre><code>public static void main(String[] args) {
      // initialize Spring
      ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring-beans.xml");
  
      App app = (App) context.getBean("app");
      app.run();
  }
  </code></pre>
  
  <p>Relevant details of AppImpl class:</p>
  
  <pre><code>@Component("app")
  public final class AppImpl implements App{    
  
      // focus of question: This autowiring works
      @Autowired
      private DAO1 dao1;
  
  
      public void run() {
          //focus of question: This works as daoclass is instantiated properly                   
          obj1s = dao1.myFind();            
  
          badJobs = runJobs(obj1s);
      }
  
      private List&lt;Obj1&gt; runJobs(final List&lt;Obj1&gt; obj1s) {        
          List&lt;Obj1&gt; jobsGoneBad = new ArrayList&lt;Obj1&gt;();
          for (Obj1 next : obj1s) {
  
              // focus of question: usage of new keyword, thus not spring container managed?
              Job job = new JobImpl(next);
              job.run();
  
          }
          return jobsGoneBad;
      }    
  }
  </code></pre>
  
  <p>Relevant details of JobImpl:</p>
  
  <pre><code>public class JobImpl implements Job {
  
      private Obj1 obj1;
  
      // focus of question: can't autowire
      @Autowired
      private DAO2 dao2;
  
      @Override
      public void run() {
          //focus of question: opDAO == null - not initialized by @Autowired
          Obj2 obj2 = dao2.myFind();        
      }
  
  }
  </code></pre>
  
  <p>Relevant details of DAO1:</p>
  
  <pre><code>@Repository("DAO1") //Focus of question: DAO1 is a repository stereotype
  public class DAO1 {
  
      myfind() { ...}
  }
  </code></pre>
  
  <p>Relevant details of DAO2:</p>
  
  <pre><code>@Repository("DAO2") //Focus of question: DAO2 is a repository stereotype
  public class DAO2 {        
  
      myfind() { ...}
  }
  </code></pre>
  
  <p>Right, so I initialize the App through a springcontext call and then succesfully instantiate a DAO1 instance through the use of @Autowired.</p>
  
  <p>Then I create an unmanaged instance of Job and want to inject "singeltonish" dependencies in that class too by using @Autowired</p>
  
  <p>Both Dao classes are spring stereotypes and scanner finds them fine.</p>
  
  <p>So my question is basically, how should I instantiate the job instance so that I can use @Autowired concept inside it?</p>
  
  <p>If I need a globally accessible applicationcontext, how do I best introduce that?</p>