Spring任务调度scheduled
2017-01-11 12:02
253 查看
1.配置spring-task.xml文件
2.web.xml配置加入以下
3.在所在的包下新建一个类
@Component
@Lazy(value=false)
public class TestTask {
@Scheduled(cron = "*/5 * * * * ?")//每隔5秒执行一次
public void test() throws Exception {
Date data = new Date();
System.out.println( data.getSeconds()+"Test is working......");
}
}
4.启动服务后效果如下
5.开发架构目录
温馨提示:本文章只是一个spring定时器测试,需要别的功能的还是需要添加别的配置文件
empty<?xml version="1.0" encoding="UTF-8"?>
2.web.xml配置加入以下
<servlet> <servlet-name>Dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
3.在所在的包下新建一个类
@Component
@Lazy(value=false)
public class TestTask {
@Scheduled(cron = "*/5 * * * * ?")//每隔5秒执行一次
public void test() throws Exception {
Date data = new Date();
System.out.println( data.getSeconds()+"Test is working......");
}
}
4.启动服务后效果如下
5.开发架构目录
温馨提示:本文章只是一个spring定时器测试,需要别的功能的还是需要添加别的配置文件