springMvc 添加定時任務


1、創建定時類

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框架配置定時任務");
    }
}

  

2、在spring的配置xml文件中開啟定時選項

<task:annotation-driven />
<context:component-scan base-package="com.timer" />  //定時器所在文包

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM