Spring Boot中配置定時任務(wù)極其簡單......下面看下實例代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import java.text.SimpleDateFormat; import java.util.Date; /** * Created by winner_0715 on 2017/4/18. */ @Configuration @EnableScheduling public class SchedulingConfig { // 每5秒執(zhí)行一次 @Scheduled (cron = "0/5 * * * * ?" ) public void scheduler() { System.out.println( "SchedulingConfig.scheduler()" + new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format( new Date())); } } |
以上所述是小編給大家介紹的Spring Boot定時任務(wù)的使用實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對服務(wù)器之家網(wǎng)站的支持!