标签:定时 size oid color actor class tor style test
1.启动类增加注解:
@EnableScheduling
@ComponentScan({"com.xxx.test"})
1 @EnableScheduling 2 @ComponentScan({"com.xxx.test"}) 3 @SpringBootApplication 4 public class MainApplication { 5 public static void main(String[] args) { 6 7 SpringApplication.run(MainApplication.class, args); 8 }
2.定时任务类增加注解:@Component :将当前类实例化注入到容器中
3.定时方法增加注解:@Scheduled(cron = "* */5 * * * ?")
1 @Component 2 public class JobTest { 3 4 private static Logger log = LoggerFactory.getLogger(JobTest.class); 5 6 /** 7 * 秒、分、时、日、月、年 8 */ 9 @Scheduled(cron = "* */5 * * * ?") 10 public void scheduleTest() { 11 log.info("系统定时任务测试开始"); 12 13 //TODO 14 15 log.info("系统定时任务测试结束"); 16 }
标签:定时 size oid color actor class tor style test
原文地址:https://www.cnblogs.com/BenNiaoXianFei/p/12752645.html