Here's an example class for anyone else looking for this answer. Note that this assumes the application context has been set into the scheduler context with the given key
Code:
/**
* @author Todd Nine
*
*/
@Component
public class AutowiredSpringBeanJobFactory extends SpringBeanJobFactory {
private SchedulerContext context;
private String applicationContextKey = "applicationContext";
@Override
protected Object createJobInstance(TriggerFiredBundle bundle)
throws Exception {
Assert.notNull(context, "Context must be set to use this object");
Assert.hasLength(applicationContextKey,
"You must set the application context key");
Object instance = super.createJobInstance(bundle);
ApplicationContext context = (ApplicationContext) this.context.get(applicationContextKey);
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(context.getAutowireCapableBeanFactory());
bpp.processInjection(instance);
return instance;
}
@Override
public void setSchedulerContext(SchedulerContext schedulerContext) {
super.setSchedulerContext(schedulerContext);
this.context = schedulerContext;
}
public void setApplicationContextKey(String applicationContextKey) {
this.applicationContextKey = applicationContextKey;
}
public String getApplicationContextKey() {
return applicationContextKey;
}