You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.0 KiB
59 lines
2.0 KiB
package com.mh.user.config; |
|
|
|
import com.mh.user.job.JobFactory; |
|
import lombok.extern.slf4j.Slf4j; |
|
import org.quartz.Scheduler; |
|
import org.springframework.context.annotation.Bean; |
|
import org.springframework.context.annotation.Configuration; |
|
import org.springframework.scheduling.quartz.SchedulerFactoryBean; |
|
|
|
/** |
|
* @author ljf |
|
* @title : Quartz配置 |
|
* @description : |
|
* @updateTime 2020-04-03 |
|
* @throws : |
|
*/ |
|
@Slf4j |
|
@Configuration |
|
public class QuartzConfig { |
|
|
|
private JobFactory jobFactory; |
|
|
|
/** |
|
* @author jinhaoxun |
|
* @description 构造器 |
|
* @param jobFactory |
|
*/ |
|
public QuartzConfig(JobFactory jobFactory){ |
|
this.jobFactory = jobFactory; |
|
} |
|
|
|
/** |
|
* @author jinhaoxun |
|
* @description 配置SchedulerFactoryBean,将一个方法产生为Bean并交给Spring容器管理 |
|
* @return SchedulerFactoryBean |
|
*/ |
|
@Bean |
|
public SchedulerFactoryBean schedulerFactoryBean() { |
|
// log.info("开始注入定时任务调度器工厂..."); |
|
System.out.println("开始注入定时任务调度器工厂..."); |
|
SchedulerFactoryBean factory = new SchedulerFactoryBean();// Spring提供SchedulerFactoryBean为Scheduler提供配置信息,并被Spring容器管理其生命周期 |
|
factory.setJobFactory(jobFactory);// 设置自定义Job Factory,用于Spring管理Job bean |
|
factory.setOverwriteExistingJobs(true);// 覆盖存在的定时任务 |
|
factory.setStartupDelay(30); //延时30秒启动定时任务,避免系统未完全启动却开始执行定时任务的情况 |
|
// log.info("注入定时任务调度器工厂成功!"); |
|
System.out.println("注入定时任务调度器工厂成功!"); |
|
// TimedTask2 timedTask2=new TimedTask2(); |
|
// timedTask2.cronJob(); |
|
// System.out.println("定点启动任务!"); |
|
return factory; |
|
} |
|
|
|
@Bean(name = "scheduler") |
|
public Scheduler scheduler() { |
|
System.out.println("进来了---------------!"); |
|
return schedulerFactoryBean().getScheduler(); |
|
|
|
} |
|
}
|
|
|