spring.xml 的 xmlns 添加:
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation添加:
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd
添加定时任务注解
<task:annotation-driven/>
添加注解扫描的包
<context:component-scan base-package="com.demo.service"/>
java文件
package com.demo.service;至于cron 百度有很多
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class DemoService {
@Scheduled(cron="0/5 * * * * ? ")
public void test(){
System.out.println("test is run.");
}
}