springMVC 定时器配置

1、在springMVC中加入

 xmlns:task="http://www.springframework.org/schema/task" 
 http://www.springframework.org/schema/task 
 http://www.springframework.org/schema/task/spring-task-3.2.xsd

2、添加定时器开关

<task:annotation-driven />

3、项目启动扫描包(我下面是多个包)

<context:component-scan base-package="com.xxx.controller,com.xxx.task"/>

4、

@Component
public class CreatTablesTask {
    
    @Autowired
    private CdrService cdrService;
    
    // 每月一号凌晨两点执行任务
   // @Scheduled(cron = "0 0  2  1 *  ? *")

  //没分钟执行一次 @Scheduled(cron = "0 0/1 * * * ?") public void TaskJob() { System.out.println("xxx");
} }
原文地址:https://www.cnblogs.com/xdcr/p/8758636.html