spring scheduler 定时器

导入所需包,在pom.xml中添加以及spring相关包

org.quartz-scheduler
quartz

application.xml
1、在xmls中添加

xmlns:task="http://www.springframework.org/schema/task"

2、在xsi:schemaLocation中添加

http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task-3.1.xsd

注意引号的位置
3、添加主键扫描信息

<!--此路径为你的定时器所在的包路径-->
<context:component-scan base-package="com.erpgw.service.client.*"/>
<task:annotation-driven/>  

<bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"/>

<!--定时器的类路径-->
<bean id="getGyTradeScheduler" class="com.erpgw.service.client.GetGyTradeScheduler"/>

4.GetGyTradeScheduler.java类

package com.erpgw.service.client;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class GetGyTradeScheduler {

    //五秒执行一次
    @Scheduled(cron="0/5 * * * * ? ") 
    public void getGyTradeAndUpdateTcTradeScheduler(){
       System.out.print("+++++++++++++++++++++++++++++++++++++++");
    }

}

你可能感兴趣的:(quartz)