微服务中定时任务的实现!

在springboot+springcloud中有些任务需要使用定时处理.

       因为在sping家族中已经集成了定时任务类.

1. 可以在启动类上添加@EnableScheduling注解发现定时组件.

2. 在需要使用定时任务的类中,使用@Component将类添加到spring容器中.

3. 在需要添加定时任务的方法上添加定时执行注解

@Scheduled(cron = "0/30 * * * * ?")
此注解后参数未cron表达式,具体需要哪些参数可以在百度中自己生成表达式

 
 

猜你喜欢

转载自www.cnblogs.com/qiujinming/p/11644809.html