在spring配置文件中添加
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
<task:annotation-driven/>
如图:
代码实现:
@Component
@Lazy(value = false)
public class Test {
@Scheduled(cron = "*/5 * * * * ?")
public void test(){
System.out.println("task start !" + DateUtil.toString(new Date()));
}
}