springmvc,springboot定时任务
实现springboot,springmvc中每多少秒进行调用方法
参考文档:
https://blog.csdn.net/xuruanshun/article/details/103368962?utm_source=app&app_version=5.3.1&code=app_1562916241&uLinkId=usr1mkqgl919blen
@Scheduled
1.在spring配置中加上task的命名空间
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
2.启用注解驱动定时任务
<!-- 配置 @Scheduled注解 -->
<task:annotation-driven />
使用案例
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class ScheduleResumeManager {
@Scheduled(cron = "0/5 * * * * ? ") // 每五秒执行一次,一秒改成0/1
public void task(){
System.out.println("1");
}
}