如何在石英触发器中访问我的 OSGi 服务?
下面,当定时器被触发时,我的服务 companyDao 为空。我是否需要将捆绑上下文提供给调度程序或作业?如果是这样,如何?
@Service
@Component(immediate = true, specVersion = "1.1", inherit = true)
public class TechnicalStageTimer implements Job {
@Reference(cardinality = MANDATORY_UNARY, policy = DYNAMIC)
protected CompanyDao companyDao;
private static final Logger LOG = LoggerFactory.getLogger(TechnicalStageTimer.class.getCanonicalName());
Scheduler scheduler;
@Activate
public void start(BundleContext context) throws Exception {
LOG.warn("Starting Timer TechnicalStageTimer");
SchedulerFactory sf = new StdSchedulerFactory();
scheduler = sf.getScheduler();
JobDetail job = JobBuilder.newJob(TechnicalStageTimer.class).build();
Trigger trigger = TriggerBuilder.newTrigger()
.withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(11, 00)) // every day at 11:00
.build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
}
@Deactivate
public void stop(BundleContext context) throws Exception {
scheduler.shutdown(true);
}
public void execute(JobExecutionContext context)
throws JobExecutionException {
LOG.warn("Timer Triggered");
List<Company> companies = companyDao.getPool();
}
}