title: Using Spring 3 autowire in a standalone Java application
body: <p>Here is my code:</p>
  
  <pre><code>public class Main {
  
      public static void main(String[] args) {
          Main p = new Main();
          p.start(args);
      }
  
      @Autowired
      private MyBean myBean;
      private void start(String[] args) {
          ApplicationContext context = 
              new ClassPathXmlApplicationContext("META-INF/config.xml");
          System.out.println("my beans method: " + myBean.getStr());
      }
  }
  
  @Service 
  public class MyBean {
      public String getStr() {
          return "string";
      }
  }
  </code></pre>
  
  <hr>
  
  <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-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; 
      &lt;context:annotation-config /&gt; 
      &lt;context:component-scan base-package="mypackage"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Why doesn't this work? I get <code>NullPointerException</code>. Is it possible to use autowiring in a standalone application?</p>