1
您好我創建了一個cron作業及其使用石英CronTrigger失敗
org.springframework.scheduling.quartz.SimpleTriggerBean
運作良好,但是當我使用CronTrigger工作didnt觸發安排我的工作都沒有扔掉它下面的任何錯誤是我的Spring配置和工作班。
<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();
}
我假設你已經在SchedulerFactoryBean來調用啓動並一直等到半夜爲你的cron表達式來觸發? – darrenmc
你有runBillingJob的引用,但我看不到它在哪裏定義。請參閱下面的答案。 –