Spring quantz--定時任務排程工具
阿新 • • 發佈:2019-01-23
1.在xml中交給spring管理的一些類
<bean id="cancelOrderJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="orderJob"/>
<property name="targetMethod" value="cancelOrder"/>
</bean>
<!-- 執行一秒後開始之行 一分鐘執行一次 -->
<bean id="cancelOrderTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="cancelOrderJobDetail"/>
<property name="startDelay" value="1000"/>
<property name="repeatInterval" value="60000"/>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="cancelOrderJobDetail"/>
</list>
</property>
<property name="triggers">
<list>
<ref bean="cancelOrderTrigger"/>
</list>
</property>
</bean>
2.建立orderJob類用來寫我們的業務邏輯
@Component("orderJob")
public class cancelOrderJob {
//To Do
}
3.這樣定時任務就配置完畢