springMvc 添加定時任務

一、建立定時類php

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

@Component
public class FlightTrainTask {
    @Scheduled(cron = "0/5 * * * * ? ") // 間隔5秒執行
    public void taskCycle() {
        System.out.println("使用SpringMVC框架配置定時任務");
    }
}

  

二、在spring的配置xml文件中開啓定時選項spring

<task:annotation-driven />
<context:component-scan base-package="com.timer" />  //定時器所在文包
相關文章
相關標籤/搜索