如何在spring中配置定时任务

2024-12-28 02:23:31
推荐回答(1个)
回答1:

1.Scheduler的配置
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">









2.Trigger的配置
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">



0/1 * * * * ?


3.JobDetail的配置
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">







4.业务类的配置


5.业务类代码
import java.util.Date;

public class MyJobA {

public void work() {
System.out.println("date: " + new Date().getTime());
}
}