1、spring容器中加入 :
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task" -------------------- xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<task:annotation-driven />
<!-- <task:annotation-driven scheduler="qbScheduler" mode="proxy" /> -->
<!-- <task:scheduler id="qbScheduler" pool-size="10" /> -->
2、在扫描到的controller中执行任务:
@RequestMapping(value="/payModel")
@Scheduled(cron="0/10 * 16 * * ?")
public void payModel( ){
List<PayModel> payModel = orderService.payModel();
System.out.println("调用payModel时间:"+new Date());
payModel = payModel==null ? new ArrayList<PayModel>():payModel;
System.out.println("定時任務:"+payModel);
}
3、注意点:执行任务时没有返回值,必须是void。