Day90
spring原生定时任务
- 导入依赖包spring-context
- 在resource层下添加spring的配置文件applicationContext.xml
- 在java层下新建类
@Component
public class SimpleJob {
//@Scheduled(fixedRate = 3000)//调度,每3秒执行
public void task1(){
System.err.println("这是原生spring的任务");
}
@Scheduled(cron = "* * * * * ?")//corn表达式 每秒
public void task2(){
System.err.println("这是原生spring的任务"+System.currentTimeMillis());
}
}
- 测试一下
public class TestMain {
@Test
public void test1() throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//阻塞一下线程
System.in.read();
}
}
Layui学习

浙公网安备 33010602011771号