1, add a namespace and xsd constraints
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, open the note in the file application.xml
<task:annotation-driven />
3, configure the scan task scan package
<context:component-scan base-package="com.task" />
4、demo
@Component
public class AutoScanTask {
@Scheduled(cron = "0/5 * * * * ? ") // 间隔5秒执行
public void autoScan() {
System.out.println("定时器执行");
}
}