spring 定时任务配置使用

1,自定义类

package com.jd.service.meeting.worker;

public class MyWorker {
public void running(){
System.out.println("hello, world!");
}
}

二 ,配置使用

 <?xml version="1.0" encoding="GBK"?> 

<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.xsd"
default-autowire="byName">

<bean id="helloWorker" class="com.jd.service.meeting.worker.MyWorker"></bean>

<bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
  <property name="triggers">
<list>
    <bean class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
    <bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="concurrent">
      <value>false</value>
    </property>
  <property name="targetObject">
      <ref bean="helloWorker" />
  </property>
  <property name="targetMethod">
    <value>running</value>
  </property>
  </bean>
  </property>
  <property name="cronExpression">
    <value>0/10 * * * * ?</value>
  </property>
  </bean>
    </list>
  </property>
  </bean>
</beans>

原文地址:https://www.cnblogs.com/bella-life-blog/p/6606204.html