title: Standalone Spring/Mybatis application autowiring returns null
body: <p>So I'm trying to write a standalone application using Spring and Mybatis. I used the same DAO's and stuff for a web application, and everything works fine. I want to be able to reuse as much of that code as possible to automate a process. I need to autowire a DAO and use it from a main() method. Right now, I have it modeled somewhat off of this question: <a href="https://stackoverflow.com/questions/16961397/autowiring-a-spring-3-2-standalone-application-fails">Autowiring a Spring 3.2 standalone application fails</a> so I have something like </p>
  
  <pre><code>public class Main{
  
      @Autowired
      DAO dao; 
  
      public Main(){
          final ApplicationContext context = new FileSystemXmlApplicationContext("src/beans.xml");
          AutowireCapableBeanFactory acbFactory = context.getAutowireCapableBeanFactory();
          acbFactory.autowireBean(this);
          System.out.println(dao); 
      }
  
      public static void main(String[] args) throws Exception {
          Main m = new main(); 
      }
  </code></pre>
  
  <p>The output is null. My DAO file is an interface and the implemented interface has something like</p>
  
  <pre><code>@Repository
  @Component
  public class DAOImpl implements DAO{
      @Autowired
      mapper m;
  
      //some methods
  }
  </code></pre>
  
  <p>How do I get it to autowire properly? </p>
  
  <p>EDIT: As suggested, I tried doing this: </p>
  
  <pre><code>public class Main{
  
      @Autowired
      DAO dao; 
  
      public Main(){
      }
  
      public static void main(String[] args) throws Exception {
          Main m = new main(); 
          final ApplicationContext context = new FileSystemXmlApplicationContext("src/beans.xml");
          AutowireCapableBeanFactory acbFactory = context.getAutowireCapableBeanFactory();
          acbFactory.autowireBean(m);
          System.out.println(m.dao); 
      }
  </code></pre>
  
  <p>It still prints out null</p>