javascript
定时任务(Spring Cloud Task)
引入依賴
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework.boot</groupId>
?? ??? ??? ?<artifactId>spring-boot-starter</artifactId>
?? ??? ?</dependency>
?? ??? ?<dependency>
?? ??? ??? ?<groupId>org.springframework.cloud</groupId>
?? ??? ??? ?<artifactId>spring-cloud-starter-task</artifactId>
?? ??? ??? ?<version>1.2.3.RELEASE</version>
?? ??? ?</dependency>
application.properties
logging.level.org.springframework.cloud.task=DEBUG
spring.application.name=service-task
1
2
編寫定時任務組件
@Component
public class ScheduledTask {
? ? /**
? ? ?* 每隔1秒執行, 單位:ms。
? ? ?*/
? ? @Scheduled(fixedRate = 1000)
? ? public void testFixRate() {
? ? ? ? System.out.println("每隔1秒執行一次:" + dateFormat.format(new Date()));
? ? }
}
啟動類添加**@EnableScheduling**注解
---------------------?
作者:_LDL?
來源:CSDN?
原文:https://blog.csdn.net/lindonglian/article/details/81329434?
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
總結
以上是生活随笔為你收集整理的定时任务(Spring Cloud Task)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用Spring Task完成定时任务
- 下一篇: 基于SpringCloud的分布式事务框