嗨,我创建了一个 cron 作业,并且通过使用它运行良好
org.springframework.scheduling.quartz.SimpleTriggerBean
但是当我使用 CronTrigger 安排我的工作时,这个工作根本没有触发,它也没有抛出任何错误,下面是我的 spring 配置和 Job 类。
<bean id="cronJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="runBillingJob" />
<property name="cronExpression" value="0 0 0 * * ?"/>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="runTestJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronJobTrigger" />
</list>
</property>
</bean>
以下是我的测试方法:
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
List<JobExecutionContext> jobs = null;
try {
jobs = context.getScheduler().getCurrentlyExecutingJobs();
for (JobExecutionContext job : jobs) {
if (job.getTrigger().equals(context.getTrigger())
&& !job.getJobInstance().equals(this)) {
logger.trace("There's another instance running, so leaving: "
+ this);
return;
}
}
logger.info("Create a BillingService instance...");
} catch (SchedulerException e) {
logger.error("", e);
return;
}
try {
triggerToController();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}