本文介绍在 spring Boot 中如何使用定时任务,使用非常简单,就不做过多说明了。
下面是代码类:
package org.springboot.sample.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
/**
* 定时任务配置类
*
* @author 单红宇(365384722)
* @myblog http://blog.csdn.net/catoop/
* @create 2016年3月21日
*/
@Configuration
@EnableScheduling
public class SchedulingConfig {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Scheduled(cron = "0/20 * * * * ?")
public void scheduler() {
logger.info(">>>>>>>>>>>>> scheduled ... ");
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28