1、创建定时类

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class FlightTrainTask {
    @Scheduled(cron = "0/5 * * * * ? ") // 间隔5秒执行
    public void taskCycle() {
        System.out.println("使用SpringMVC框架配置定时任务");
    }
}

  

2、在spring的配置xml文件中开启定时选项

<task:annotation-driven />
<context:component-scan base-package="com.timer" />  //定时器所在文包

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-03
  • 2021-09-10
  • 2021-10-02
  • 2021-10-25
  • 2021-12-22
  • 2022-02-25
相关资源
相似解决方案