Spring boot项目中使用定时任务 Spring task的步骤

1.在启动类上面配置注解

@EnableScheduling
@EnableAsync
@SpringBootApplication
public class DdingApplication {

    public static void main(String[] args) {
        SpringApplication.run(DdingApplication.class, args);
    }

}

2在目标工具类上面配置注解以及代码

@Component
public class Test {  
//    清除缓存的会员数据
    @Async
    @Scheduled(cron = "0/5 * * * * *")
    public void Time() {
        System.out.println(111);
    }

3.启动Springboot项目

2021-05-24 09:57:03.411  INFO 12968 --- [           main] com.example.dding.DdingApplication       : Starting DdingApplication using Java 1.8.0_191 on LAPTOP-OL00SML3 with PID 12968 (G:\20210327\ceshiDaima\target\classes started by 12964 in G:\20210327\ceshiDaima)
2021-05-24 09:57:03.413  INFO 12968 --- [           main] com.example.dding.DdingApplication       : No active profile set, falling back to default profiles: default
2021-05-24 09:57:04.229  INFO 12968 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-05-24 09:57:04.236  INFO 12968 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-05-24 09:57:04.236  INFO 12968 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.46]
2021-05-24 09:57:04.317  INFO 12968 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-05-24 09:57:04.317  INFO 12968 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 842 ms
2021-05-24 09:57:05.106  INFO 12968 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-24 09:57:05.117  INFO 12968 --- [           main] com.example.dding.DdingApplication       : Started DdingApplication in 2.051 seconds (JVM running for 2.986)
2021-05-24 09:57:05.119  INFO 12968 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state LivenessState changed to CORRECT
2021-05-24 09:57:05.120  INFO 12968 --- [           main] o.s.b.a.ApplicationAvailabilityBean      : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC
111
111
111
111
111
111
111
111
111
111
111
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值