报错如下:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'systemOpenControlTask' defined in file [...\sys\quartz\job\SystemOpenControlTask.class]:
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzScheduler' defined in class path resource
[org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.class]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Jobs added with no trigger must be durable.
既然都使用了Spring-Boot,肯定不会再用xml的配置方式来配置定时任务了吧?
如果你是使用的配置类,那么你只需要为你的JobDetail增加一个持久储存的配置:
不废话,我的代码如下:
@Configuration
public class QuartzConfig {
@Bean
public JobDetail getSystemOpenControlJobDetail(){
return JobBuilder.newJob(SystemOpenControlTask.class).withIdentity("SystemOpenControlJob").storeDurably(true).build();
}
}
注意:其中的重点部分就是storeDurably,该方法参数传“TRUE”就行了,表示任务完成之后是否会持久存储。
如果是XML配置的,可以为Job使用如下配置:
<property name="durability" value="true" />
|