applicationContext.xml
1. 增加配置
<!-- 开启定时任务 -->
<task:annotation-driven />
<!-- 开启注解 -->
<context:annotation-config />
<!-- 指定相关的包路径 -->
<context:component-scan base-package="com.xxx.xxx"/>
<task:annotation-driven />
taks来自
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
2. 创建定时任务类
@Component
@Slf4j
public class CloseOrderTask {
@Scheduled(cron="0 */1 * * * ?") //(每个1分钟的整数倍执行一次)
public void closeOrderTaskV1(){
log.info("关闭订单定时任务启动");
log.info("关闭订单定时任务结束");
}
}
3.在线cron表达式生成器
http://cron.qqe2.com/