title: What is causing my autowired object to throw a Null Pointer Exception?
body: <p>I have a public final class that extends <code>Configured</code> and implements <code>Tool</code> that refuses to see an autowired variable. This class is passed to the static <code>ToolRunner.run</code> method and I'm not sure what impact I should expect from this added layer of complexity.</p>
  
  <p>I've offloaded the logic of the <code>context.getBean</code> to a separate class and the autowiring works but introduces more bugs (nulls the configuration of the ToolRunner).  The code for this separate class is a carbon copy of the code in the <code>Driver</code> class and is annotated as <code>@Component</code>. Why the <code>Autowired</code> works for a separate class but not this one is unknown to me.</p>
  
  <p>Here's the code from the Driver class:</p>
  
  <pre><code>@Component
  public final class Driver extends Configured implements Tool {
  private static Driver driver = new Driver();
  @Autowired
  private Connection connection;
  
  public static void main(String[] args) throws Exception{
  int exitCode = ToolRunner.run(new Configuration(),driver, args);
  }
  
  @Override
  public int run(String[] args) throws Exception{
  AbstractApplicationContext context = new AnnotationConfigApplicationContext(HdfsConfig.class);
  driver = context.getBean(Driver.class);
  \\and it continues till I hit my getConnection NPE
  </code></pre>
  
  <p>Here's HdfsConfig.class:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = {"shared.folder"}
  public class HdfsConfig{
  
  @Bean
  @Scope(BeanDefinition.SCOPE_PROTOTYPE)
  public org.apache.hadoop.conf.Configuration configuration = new Configuration();
  \\So on and so on until I return my configuration
  </code></pre>
  
  <p>What I really want to do is retain my ToolRunner info and connection object in the class with everything populated and happy. I suspect something regarding the nature of my <code>Driver</code> variable is breaking things but the reason is escape my feeble brain.</p>