I have a public final class that extends Configured
and implements Tool
that refuses to see an autowired variable. This class is passed to the static ToolRunner.run
method and I'm not sure what impact I should expect from this added layer of complexity.
I've offloaded the logic of the context.getBean
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 Driver
class and is annotated as @Component
. Why the Autowired
works for a separate class but not this one is unknown to me.
Here's the code from the Driver class:
@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
Here's HdfsConfig.class:
@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
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 Driver
variable is breaking things but the reason is escape my feeble brain.