- 配置applicationContext.xml
在文件头中添加
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
开启注解扫描
<context:component-scan base-package="com.lee.xx" />
启动定时任务
<task:annotation-driven/>
- 编写任务类
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class MyTest {
@Scheduled(cron = "*/10 * * * * ?")//每隔10秒执行一次
public void test() throws Exception {
System.out.println("定时任务执行......");
}
}
corn表达式写法百度。。。。。