Spring-Task 的应用(配置文件方式)

第一步:编写作业类

即普通的pojo,如下:

Java代码  收藏代码
  1. public class productListTask {  
  2.     public void findProduct() {  
  3.         System.out.println(“任务进行中。。。”);  
  4.     }  
  5. }

第二步:在spring配置文件头中添加命名空间及描述

Xml代码  收藏代码
    1. <beans xmlns="http://www.springframework.org/schema/beans"  
    2.     xmlns:task="http://www.springframework.org/schema/task"   
    3.     。。。。。。  
    4.     xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"

第三步:spring配置文件中设置具体的任务

Xml代码  收藏代码
<bean id="productListTask" class="com.common.util.ProductListTask" scope="singleton" init-method="findProductList" />
<task:scheduled-tasks>
<task:scheduled ref="productListTask" method="findProduct" cron="0 0 * * * ?"/>
</task:scheduled-tasks>

说明:ref参数指定的即bean的id,method指定的即需要运行的方法,cron我写的是到整点执行一次.

 

 

 
posted @ 2015-05-07 17:08  现世安好  阅读(495)  评论(0)    收藏  举报