Spring任务调度,Quartz Scheduler时间:2021-01-22 19:09:28新建bean.xml文件,代码如下: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- 定义一个任务调度器 --> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref local="estimateLogTriggerQuartz"/> </list> </property> </bean> <!-- 配置触发器调度的bean --> <bean id="estimateLog" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 引用一个bean --> <property name="targetObject" ref="estimateLogTrigger"/> <!-- 指定目标bean的方法 --> <property name="targetMethod" value="doSaveEstimateLog"/> </bean> <!-- 配置触发器 --> <bean id="estimateLogTriggerQuartz" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="estimateLog"/> <!-- 每隔3秒执行一次 --> <property name="cronExpression" value="0/3 * * * * ?"/> </bean> <!-- 被调度的bean --> <bean id="estimateLogTrigger" class="mypack.EstimateLogTrigger"> </bean></beans> 新建类EstimateLogTrigger,代码如下: package mypack;public class EstimateLogTrigger { public void doSaveEstimateLog(){ System.out.println("test..."); }} 新建测试类,代码如下: package mypack;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestMain { public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"bean.xml"}); }} 测试执行。。。