spring定时任务+springBoot

第一步入口类:

@SpringBootApplication
@EnableDiscoveryClient //开启服务注册
@EnableFeignClients //开启负载均衡
@EnableScheduling//开启计划任务支持
public class FrontApplication {

   protected final static Logger logger = LoggerFactory.getLogger(FrontApplication.class);

   public static void main(String[] args) {
      SpringApplication.run(FrontApplication.class, args);
      logger.info("Application is success!");
   }
}

第二步:

@Scheduled(cron = "0 0/1 * * * ?")
public void automatic(){
    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String format1 = format.format(new Date());
    log.info("远程自动控制执行了:"+format1);
  
}

猜你喜欢

转载自blog.csdn.net/xm526489770/article/details/80064244